高手们帮我看看DELPHI调用VC写的DLL问题出在哪里?

telstar 2005-05-20 10:54:21
1、我用VC6.0做了一个MFC DLL
输出函数定义如下:
extern "C" _declspec(dllexport) void GetCheckData(double * mWeight, double * mHight);
2、我用以下VC代码在调用该函数,没有任何问题:
void CAppDlg::OnButton1()
{
// TODO: Add your control notification handler code here
double mfWeight=0.0,mfHight=0.0;
CString stra;

HINSTANCE hin;
typedef (*myfun)(double*,double*);
myfun proc;

hin=::LoadLibrary("RecData.dll");
if (hin != NULL)
{
proc=(myfun)::GetProcAddress(hin,"GetCheckData");
proc(&mfWeight,&mfHight);
}

FreeLibrary(hin);
}
3、我用以下DELPHI代码调用,报MFC42.DLL中内存访问错误
type
TgetData = function (l,w:pointer): HResult; stdcall;
procedure TForm1.Button1Click(Sender: TObject);
var
lWeight,lHigh:Double;
lb:tHandle;
getCheckData:tGetData;
begin
lb := loadlibrary('E:\com\RecData\release\recData.dll');
if lb <> 0 then
begin
getCheckData := GetProcAddress(lb,'GetCheckData');
if assigned(getCheckData) then
getCheckData(@lWeight,@lHigh);
end;
end;
将TgetData = function (l,w:pointer): HResult; stdcall;
改为TgetData = function (var l,w:double): HResult; stdcall;

仍然不行

高手们帮忙啊
...全文
102 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sboom 2005-05-21
  • 打赏
  • 举报
回复
DELPHI默认__fastcall寄存器传递参数,你指定__stdcall才行。
telstar 2005-05-20
  • 打赏
  • 举报
回复
to bohut(伯虎):
加AFX_MANAGE_STATE(AfxGetStaticModuleState());后编译通不过,报错信息如下:
Compiling...
RecData.cpp
Linking...
mfcs42d.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in RecData.obj
mfcs42d.lib(dllmodul.obj) : error LNK2005: __pRawDllMain already defined in RecData.obj
mfcs42d.lib(dllmodul.obj) : warning LNK4006: _DllMain@12 already defined in RecData.obj; second definition ignored
mfcs42d.lib(dllmodul.obj) : warning LNK4006: __pRawDllMain already defined in RecData.obj; second definition ignored
Creating library Debug/RecData.lib and object Debug/RecData.exp
Debug/RecData.dll : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

RecData.dll - 3 error(s), 2 warning(s)
柯本 2005-05-20
  • 打赏
  • 举报
回复
试试不用MFC的DLL,用win32 Dynamic-link library
我试过,没问题(MFC没试过)
telstar 2005-05-20
  • 打赏
  • 举报
回复
to orbit(走了走了) , bohut(伯虎) :
是release版的
刚才我试了一下,release版的用vc程序调用都有问题,delphi程序更加不行。所以可以肯定是dll的问题。
下面是我的dll定义文件内容,劳驾帮我看看问题在哪:
// RecData.cpp : Defines the initialization routines for the DLL.
//

#include "stdafx.h"
#include <afxdllx.h>
#include "RecDlg.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern "C" _declspec(dllexport) void GetCheckData(double * mWeight, double * mHight);
/*
extern "C" _declspec(dllexport) void GetCheckData(double * mWeight, double * mHight)
{
CRecDlg mRecWindows;
mRecWindows.DoModal();

if(mRecWindows.m_flag)
{
char * stopstring;
*mWeight=strtod(mRecWindows.m_Weight,&stopstring);
*mHight=strtod(mRecWindows.m_Hight,&stopstring);
// return 1;
}//else return 0;
mRecWindows.CloseWindow();
}
*/
static AFX_EXTENSION_MODULE RecDataDLL = { NULL, NULL };

extern "C" int APIENTRY
DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
// Remove this if you use lpReserved
UNREFERENCED_PARAMETER(lpReserved);

if (dwReason == DLL_PROCESS_ATTACH)
{
TRACE0("RECDATA.DLL Initializing!\n");

// Extension DLL one-time initialization
if (!AfxInitExtensionModule(RecDataDLL, hInstance))
return 0;

// Insert this DLL into the resource chain
// NOTE: If this Extension DLL is being implicitly linked to by
// an MFC Regular DLL (such as an ActiveX Control)
// instead of an MFC application, then you will want to
// remove this line from DllMain and put it in a separate
// function exported from this Extension DLL. The Regular DLL
// that uses this Extension DLL should then explicitly call that
// function to initialize this Extension DLL. Otherwise,
// the CDynLinkLibrary object will not be attached to the
// Regular DLL's resource chain, and serious problems will
// result.

new CDynLinkLibrary(RecDataDLL);
}
else if (dwReason == DLL_PROCESS_DETACH)
{
TRACE0("RECDATA.DLL Terminating!\n");
// Terminate the library before destructors are called
AfxTermExtensionModule(RecDataDLL);
}
return 1; // ok
}


void GetCheckData(double * mWeight, double * mHight)
{
//AFX_MANAGE_STATE(AfxGetStaticModuleState());
CRecDlg mRecWindows;

mRecWindows.DoModal();

if(mRecWindows.m_flag)
{
char * stopstring;
*mWeight=strtod(mRecWindows.m_Weight,&stopstring);
*mHight=strtod(mRecWindows.m_Hight,&stopstring);
// return 1;
}//else return 0;
// mRecWindows.CloseWindow();
}
吹泡泡的小猫 2005-05-20
  • 打赏
  • 举报
回复
dll是不是Debug版的
bohut 2005-05-20
  • 打赏
  • 举报
回复
dll中的输出函数中开始的地方加一句:

AFX_MANAGE_STATE(AfxGetStaticModuleState());

试试看
flyelf 2005-05-20
  • 打赏
  • 举报
回复
delphi调用vc的dll,要求接口是__stdcall的方式

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧