在程序中定义了一个结构体,如何将结构体传入动态连接库(Dll),并返回结构体值。
解决方案 »
- 哪位大侠能帮我详细解释一下这段代码啊
- 在编辑框贴图遇到一些问题,跪求&&等待高手指点,谢谢、非常谢谢.
- 熟悉STL 的高手给帮忙看一下这个问题
- 请问VC是怎么设置断点的
- 怎样在VC6里用CImage?
- 【求助】请问有关flash播放器源码的问题!(100分,谢谢!)
- 问个小问题?
- 我有两个文件CONTROL.H,CONTROL.ODL,怎样在我的对话框程序内引用这两个文件
- 在程序中调用BCP,不执行。在ENTERPRISE MANAGE中执行是好的。
- 创建数据库的问题,创建失败
- 请问_beginthreadex 在win32下内部是调用CreateThread Win32函数来创建线程的吗?
- 如何让cpropertysheet显示出来后,对里面的每个page都已经create?
你在DLL中定义相同结构
把new出的结构的指针p传入DLL接口,DLL通过:
YourStruct* pStruct = reinterpret_cast<YourStruct*>(p);
这样就可以了.
不知道你是否是这个意思?
typedef struct{
int x1;
int x2;
int x3;
int x4;
}test;
然后我想把对此结构体的赋值写在dll中,我就是不知到如何传到dll中,如何返回!
{ // ptest 值改变并返回之}int Write(test *ptest);
{ //同上}
--------------------Configuration: InsSys - Win32 Debug--------------------
Compiling...
InsSys.cpp
Generating Code...
Compiling...
InsDBDate.cpp
Generating Code...
Linking...
InsSys.obj : error LNK2001: unresolved external symbol "public: int __thiscall DBData::read(int,struct test *)" (?read@DBData@@QAEHHPAUtest@@@Z)
InsSys.obj : error LNK2001: unresolved external symbol "struct test * ptest" (?ptest@@3PAUtest@@A)
Debug/InsSys.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
Creating browse info file...InsSys.exe - 3 error(s), 0 warning(s)
EXPORT bool WRITE(extern test *ptest)
{
memset(&ptest, 0x00, sizeof(ptest));
ptest[0].x1=2+1;
ptest[0].x2=2+2;
ptest[0].x3=2+3;
ptest[0].x4=2+4;
return true;}
在exe中写一个函数调用
int read(test *ptest)
{
int a;
a=0;
typedef bool (_cdecl *TESTDLL)(test *ptest);
HINSTANCE hmod;
TESTDLL lpproc;
hmod = ::LoadLibrary ("GetCell.dll");
if(hmod==NULL)
{
return 0;
}
lpproc = (TESTDLL)::GetProcAddress(hmod,"WRITE");
if(lpproc)
{
a=ptest[0].x1;
a=ptest[0].x2;
a=ptest[0].x3;
a=ptest[0].x4;
}
else
{
return 0;
}
FreeLibrary(hmod);
return 1;
}
结果lpproc没有值,这是怎么回事?