
Delphi写的DLL在C++里怎样写函数的原型?
目前我是这样做的,但是会乱码.serialNum是要传出的,serialNum取出是乱码.DelphiDLL:functionGetNewSN(computerNum:P...
目前我是这样做的,但是会乱码.serialNum 是要传出的,serialNum取出是乱码.
Delphi DLL:
function GetNewSN(computerNum:PChar;serialNum:PChar):Integer;export; stdcall;
C++
typedef int (WINAPI * GetNewSN)(LPTSTR,LPTSTR);
调用:
GetNewSN pfGetNewSN=NULL;
int nResult;
LPTSTR lpComputerNo;
lpComputerNo=_T("01");
char* lpSN;
lpSN=new char[12];
HINSTANCE hinst=::LoadLibrary(_T("GenerateSN.dll"));
if(NULL!= hinst)
{
std::cout<<"Load library Completed ."<<std::endl;
pfGetNewSN=(GetNewSN)GetProcAddress(hinst,"GetNewSN");
if(NULL!=pfGetNewSN)
{
std::cout<<"Load Function Completed ."<<std::endl;
int rut=pfGetNewSN(lpComputerNo,lpSN);
//调用正常,lpSN乱码
switch(rut)
{
case cResultPass:
{
//开始写序号
std::cout<<"SN:"<<lpSN<<std::endl;
break;
}
default:
{
std::cout<<"Load Function Error ."<<std::endl;
//取得序号错误
}
}
}
}else
std::cout<<"Load library error !"<<std::endl;
FreeLibrary(hinst);
我已经搞定了. ^-^
改写C++代码.如下
typedef int (WINAPI* GetNewSN)(LPTSTR,char **);
....
char* lpSN=(char *)malloc(255);
....
int rut=pfGetNewSN(lpComputerNo,&lpSN);
..... 展开
Delphi DLL:
function GetNewSN(computerNum:PChar;serialNum:PChar):Integer;export; stdcall;
C++
typedef int (WINAPI * GetNewSN)(LPTSTR,LPTSTR);
调用:
GetNewSN pfGetNewSN=NULL;
int nResult;
LPTSTR lpComputerNo;
lpComputerNo=_T("01");
char* lpSN;
lpSN=new char[12];
HINSTANCE hinst=::LoadLibrary(_T("GenerateSN.dll"));
if(NULL!= hinst)
{
std::cout<<"Load library Completed ."<<std::endl;
pfGetNewSN=(GetNewSN)GetProcAddress(hinst,"GetNewSN");
if(NULL!=pfGetNewSN)
{
std::cout<<"Load Function Completed ."<<std::endl;
int rut=pfGetNewSN(lpComputerNo,lpSN);
//调用正常,lpSN乱码
switch(rut)
{
case cResultPass:
{
//开始写序号
std::cout<<"SN:"<<lpSN<<std::endl;
break;
}
default:
{
std::cout<<"Load Function Error ."<<std::endl;
//取得序号错误
}
}
}
}else
std::cout<<"Load library error !"<<std::endl;
FreeLibrary(hinst);
我已经搞定了. ^-^
改写C++代码.如下
typedef int (WINAPI* GetNewSN)(LPTSTR,char **);
....
char* lpSN=(char *)malloc(255);
....
int rut=pfGetNewSN(lpComputerNo,&lpSN);
..... 展开
2个回答
展开全部
dll也就是一个可以被所有编程语言调用的函数,它的写法和函数是一模一样。你只要理解DELPHI DLL的功能,用C++写一个也不是什么难事的。DLL一般功能都比较简单,解决的最终问题的数量也很有限。当然洛,对于有窗体DLL就不能这样说了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询