高分,都进来看看

topshow1983 2009-07-20 10:48:18
关于delphi调用vc生成dll的问题。我用vc生成的dll,delphi调用会报错,但是一直找不到问题所在,请大家进来帮我看看。
#define _TM_OS2
#include "stdafx.h"
#include "atmi.h"

bool WINAPI DllMain( HMODULE hModule, DWORD dwReason, LPVOID lpvReserved )
{
return TRUE;
}

LRESULT WINAPI TpStrCall1(char *ServiceName, char *Str)
{
MessageBox( 0, ServiceName, "信息!", 0 );
MessageBox( 0, Str, "信息!", 0 );
return(0);
}

LRESULT WINAPI TpStrCall(char *ServiceName, char *SndStr, char *RevStr)
{
char *sendbuf, *rcvbuf;
long rcvlen;
int ret;

if (strlen(SndStr) > 300)
{
MessageBox( 0, "字符串超出指定长度!", "错误!", 0 );
return(tperrno);
}

if (tpinit((TPINIT *) NULL) == -1)
{
MessageBox( 0, "连接初始化错误!", "错误!", 0 );
return(tperrno);
}

if((sendbuf = (char *) tpalloc("STRING", NULL, sizeof(SndStr))) == NULL)
{
MessageBox( 0, "分配发送字符串出错!", "错误!", 0 );
tpterm();
return(tperrno);
}

if((rcvbuf = (char *) tpalloc("STRING", NULL, sizeof(SndStr)*2)) == NULL)
{
MessageBox( 0, "分配接收字符串出错!", "错误!", 0 );
tpfree(sendbuf);
tpterm();
return(tperrno);
}

strcpy(sendbuf, SndStr);

ret = tpcall(ServiceName, (char *)sendbuf, 0, (char **)&rcvbuf, &rcvlen, (long)0);
if(ret == -1)
{
MessageBox( 0, "tpcall失败!", "错误!", 0 );
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
return(tperrno);
}

strcpy(RevStr, rcvbuf);
tpfree(sendbuf);
tpfree(rcvbuf);
tpterm();
return(0);
}

LRESULT WINAPI check_newno(char *newno, int flag)
{
int m, len;
int i, j, k, l;

j = 0;
len = strlen(newno) - 1;
m = (len - 1) % 2;

for( i = len - 1; i >= 0; i-- )
{
if(newno[i] > '9' || newno[i] < '0')
return -1;
if( i%2 == m )
l = (newno[i] - '0') * 2;
else
l = newno[i] - '0';
j = j + l / 10 + l % 10;
}

j = j % 10;

if( j == 0 )
j = 10;

k = 10 - j;

if(flag == TRUE)
{
if ( (char) newno[len] == (char) ('0' + k) )
return 0;
else
return -1;
}
else
{
newno[len] = '0' + k;
return 0;
}

}
delphi调用程序如下:
function TpStrCall(ServName: pChar; SndStr: pChar; RevStr: pChar): integer;
stdcall; external 'TuxAPI.dll';
function check_newno(newno: PChar; flag: Integer): integer;
stdcall; external 'TuxAPI.dll';
function MacHash(inputstr: PChar; outputstr: PChar; flat: PChar): integer;
...全文
163 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
angeryi 2009-08-01
  • 打赏
  • 举报
回复
Delphi不熟悉,估计是出现你的调用方式上吧?
jyh_baoding 2009-08-01
  • 打赏
  • 举报
回复
好象和函数声明有关.没用DELPHI,帮顶
songtao_01 2009-07-31
  • 打赏
  • 举报
回复
导入函数声明定义为_declspec(dllimport) void passcal * function1();
topshow1983 2009-07-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhoujianhei 的回复:]
需要调用的函数都要导出

extern "C" __declspec(dllexport)
LRESULT WINAPI check_newno(char *newno, int flag)
{
...
}

[/Quote]
报的其它错:无法定位程序输入点 check_newno 于动态链接库 TuxAPI.dll上
topshow1983 2009-07-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 lin 的回复:]
引用 2 楼 killbug2004 的回复:
dll中导出函数声明和定义都加上stdcall修饰,同delphi中使用要一致


误导,请你看看WINAPI的宏定义究竟是啥??

LZ,俺建议你直接调试这个DLL,看看究竟是哪里出错。
[/Quote]

报的其它错:无法定位程序输入点 check_newno 于动态链接库 TuxAPI.dll上
topshow1983 2009-07-20
  • 打赏
  • 举报
回复
直接调用报的:应用程序正常初始化(0xc000007b)失败
Wenxy1 2009-07-20
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 zhoujianhei 的回复:]
需要调用的函数都要导出

extern "C" __declspec(dllexport)
LRESULT WINAPI check_newno(char *newno, int flag)
{
...
}

[/Quote]

顶这个。
zhoujianhei 2009-07-20
  • 打赏
  • 举报
回复
需要调用的函数都要导出

extern "C" __declspec(dllexport)
LRESULT WINAPI check_newno(char *newno, int flag)
{
...
}
Lin 2009-07-20
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 killbug2004 的回复:]
dll中导出函数声明和定义都加上stdcall修饰,同delphi中使用要一致
[/Quote]

误导,请你看看WINAPI的宏定义究竟是啥??

LZ,俺建议你直接调试这个DLL,看看究竟是哪里出错。
topshow1983 2009-07-20
  • 打赏
  • 举报
回复
在哪儿加?
killbug2004 2009-07-20
  • 打赏
  • 举报
回复
dll中导出函数声明和定义都加上stdcall修饰,同delphi中使用要一致
topshow1983 2009-07-20
  • 打赏
  • 举报
回复
怎么没人跟帖
bylea 2009-07-20
  • 打赏
  • 举报
回复
WINAPI ------>pascal 试试
KHacker_001 2009-07-20
  • 打赏
  • 举报
回复
导出函数声明很重要!
songtao_01 2009-07-20
  • 打赏
  • 举报
回复
可能是数据对齐方式不一样
XD王 2009-07-20
  • 打赏
  • 举报
回复
需要导出的函数 声明为
void _declspec(dllexport) __stdcall function1()
void _declspec(dllexport) __stdcall function2()
void _declspec(dllexport) __stdcall function3()

添加一个Def文件:
LIBRARY DefClass
EXPORTS
function1 @ 1
function2 @ 2
function3 @ 3
oyljerry 2009-07-20
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 topshow1983 的回复:]
引用 5 楼 zhoujianhei 的回复:
需要调用的函数都要导出

extern "C" __declspec(dllexport)
LRESULT WINAPI check_newno(char *newno, int flag)
{
...
}


报的其它错:无法定位程序输入点 check_newno 于动态链接库 TuxAPI.dll上
[/Quote]
check_newno 这个函数你要导出.

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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