2010年1月1日 星期五

c++ tech

in test.dll (比方說梯形法求積分 a,b上下極限. n 為切的塊數)

.h 檔
extern "C" __declspec( dllexport ) float __stdcall trapzd(float (*func)(float), float a, float b, int n);

.cpp 檔
float __stdcall trapzd(float (*func)(float), float a, float b, int n)
{ float x,tnm,sum,del;
static float s;
int it,j;
if (n == 1) { return (s=0.5*(b-a)*((*func)(a)+(*func)(b))); } else { for (it=1,j=1;j for (sum=0.0,j=1;j <=it;j++,x+=del) sum += (*func)(x);
s=0.5*(s+(b-a)*sum/tnm);
return s; } }


Declare Function trapzd Lib "test.dll" Alias "trapzd@16" (ByVal fn As Long, ByVal a As Single , ByVal b As Single , ByVal n As Integer) As Single 'double 的不行

Function vbsquare(ByVal x As signle) As Single 'double 的不行
vbsquare = x * x
End Function

sub test
dim a as single a=trapzd(addressof vbsquare,0,1,5)
end sub

但这样做是有条件的,如果 test.dll 中的 float (*func)(float) 用的是 stdcall 调用约定,你就能成功。否则,就算返回了正确的计算结果程序也会崩溃一下,那时没法解决的。
============================================
install boost for Code::blocks
http://wiki.codeblocks.org/index.php?title=BoostWindowsQuickRef
boost中文說明
http://www.easycpp.org/book/boost官方手册
========================================================= learn open gl
http://xoax.net/comp/cpp/opengl/index.php
=========================================================
找不到 xxxx.h 時

vc++2008
0.ctrl+shift+N -> 一般 -> 空專案
1.方案總管內 滑鼠右鍵->加入->現有項目-> all files required
2.方案總管內 滑鼠右鍵點->屬性->左方c/c++->其它include目錄 加入 "xxxx.h"
(2.先行編譯標頭檔->建立/使用先行編譯標頭->選 未使用先行編譯標頭檔)
c::b
2.in management, mouse right bottom->properties->project settings->project's build options->search directories->compiler-> add "xxxx.h"


==================================================
ex. constructor in c++
class file {
public:
file();
file(file&);
file(const char*);
}

file(); // file fileA;
file(file&); // file fileA=fileB;
file(const char*); file fileA("hello.cpp");

ex. multi inheritance 在繼承兩class, 但兩class有同一父class時
class box: virtual public rect{...};
class frame:virtual public rect{...};
class framebox:public box, public frame{...};

ex. virtual 動態連結
class Door {
public:
virtual void open(); //不知啥門
};

class CarDoor: public Door {
public:
void open(){...}; //開車門
};

class Person {
public:
void OpenDoor(Door& D) const {D.Open();} // 人開門,程式compile時不知開車門或啥門
};

ex. C is B, B is A
class A {public: virtual void f();};
class B: public A {void f();};
class C: public B {void f();};
void main() {
C c;
A *a= &c;
a->f(); // 用的是C::f();
}

沒有留言:

張貼留言