我写了个DLL,里面有一个导出函数,我在调试他的时候发现,他一执行return语句就出错,不懂为啥,我在想是不是函数的调用约定不对,请高手指教,代码如下://////////////////////////////////////////////////////////////////////////
// File name: modNoteinfo.cpp
#include <process.h> //this header file is define the _beginthread function
#include <afxwin.h>
#include "modNoteinfo.h" //in this file define the output interface
#include "stdafx.h"
//////////////////////////////////////////////////////////////////////////
// Global variables
//
static HMODULE g_hModule = NULL ; // DLL module handle
static HMODULE g_hGMSDLL = NULL; // Note mode link library handle
static char* g_pszLastError = NULL; // Last Error Message
static int g_nRef = 0; // The library using times countBOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, void* lpReserved)
{
switch (dwReason )
{
case DLL_PROCESS_ATTACH:
if (NULL == g_hModule)
g_hModule = (HMODULE)hModule ;
g_nRef ++;
break;
case DLL_PROCESS_DETACH:
g_nRef --;
if (0 == g_nRef && NULL != g_pszLastError)
{
delete[]g_pszLastError;
g_pszLastError = NULL;
}
if (NULL != g_hGMSDLL)
{
FreeLibrary(g_hGMSDLL);
g_hGMSDLL = NULL;
}
break;
default:
break;
}
return TRUE ;
}STDINTMETHOD InitNoteInfo(int nCommport)
{
if (NULL == g_pszLastError)
g_pszLastError = new char[1024];
if (NULL == g_hGMSDLL)
g_hGMSDLL = LoadLibrary("..\\bin\\SMS.dll");
Sms_Connection pProcConnGSM;
pProcConnGSM = (Sms_Connection)GetProcAddress(g_hGMSDLL, "Sms_Connection");
CString strMobileType[265];
CString strCopyToCOM[265];
int nRet;
CString strCopyright;
strCopyright = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";
nRet = pProcConnGSM(strCopyright, nCommport, 19200, strMobileType, strCopyToCOM);
TRACE("InitNoteInfo(int): nRet= {%d}", nRet);
if (0 == nRet)
{
if (NULL == g_pszLastError)
g_pszLastError = new char[1024];
strcpy(g_pszLastError, "Initializing the GMS Modem happen error!");
}
return nRet;
}......../////////////////////////////////////////////////////////////////////////////
//
// File: modNoteinfo.h
#ifndef __MODNOTEINFO_H__
//
// Macro defines
//
// this macro defined for avoid this header file replay import
#define __MODNOTEINFO_H__
//
// STDINTMETHOD macro is define this library standard export method
#define STDINTMETHOD extern "C" int __stdcall
// all interface method of this library provide listSTDINTMETHOD InitNoteInfo(int);
#define STDINTMETHOD
.......
#endif
// File name: modNote.def
LIBRARY modNoteinfo.dll
DESCRIPTION 'cwcyClient -- Note group broad module'EXPORTS
InitNoteInfo @2 PRIVATE
......
// File name: modNoteinfo.cpp
#include <process.h> //this header file is define the _beginthread function
#include <afxwin.h>
#include "modNoteinfo.h" //in this file define the output interface
#include "stdafx.h"
//////////////////////////////////////////////////////////////////////////
// Global variables
//
static HMODULE g_hModule = NULL ; // DLL module handle
static HMODULE g_hGMSDLL = NULL; // Note mode link library handle
static char* g_pszLastError = NULL; // Last Error Message
static int g_nRef = 0; // The library using times countBOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, void* lpReserved)
{
switch (dwReason )
{
case DLL_PROCESS_ATTACH:
if (NULL == g_hModule)
g_hModule = (HMODULE)hModule ;
g_nRef ++;
break;
case DLL_PROCESS_DETACH:
g_nRef --;
if (0 == g_nRef && NULL != g_pszLastError)
{
delete[]g_pszLastError;
g_pszLastError = NULL;
}
if (NULL != g_hGMSDLL)
{
FreeLibrary(g_hGMSDLL);
g_hGMSDLL = NULL;
}
break;
default:
break;
}
return TRUE ;
}STDINTMETHOD InitNoteInfo(int nCommport)
{
if (NULL == g_pszLastError)
g_pszLastError = new char[1024];
if (NULL == g_hGMSDLL)
g_hGMSDLL = LoadLibrary("..\\bin\\SMS.dll");
Sms_Connection pProcConnGSM;
pProcConnGSM = (Sms_Connection)GetProcAddress(g_hGMSDLL, "Sms_Connection");
CString strMobileType[265];
CString strCopyToCOM[265];
int nRet;
CString strCopyright;
strCopyright = "//上海迅赛信息技术有限公司,网址www.xunsai.com//";
nRet = pProcConnGSM(strCopyright, nCommport, 19200, strMobileType, strCopyToCOM);
TRACE("InitNoteInfo(int): nRet= {%d}", nRet);
if (0 == nRet)
{
if (NULL == g_pszLastError)
g_pszLastError = new char[1024];
strcpy(g_pszLastError, "Initializing the GMS Modem happen error!");
}
return nRet;
}......../////////////////////////////////////////////////////////////////////////////
//
// File: modNoteinfo.h
#ifndef __MODNOTEINFO_H__
//
// Macro defines
//
// this macro defined for avoid this header file replay import
#define __MODNOTEINFO_H__
//
// STDINTMETHOD macro is define this library standard export method
#define STDINTMETHOD extern "C" int __stdcall
// all interface method of this library provide listSTDINTMETHOD InitNoteInfo(int);
#define STDINTMETHOD
.......
#endif
// File name: modNote.def
LIBRARY modNoteinfo.dll
DESCRIPTION 'cwcyClient -- Note group broad module'EXPORTS
InitNoteInfo @2 PRIVATE
......
解决方案 »
- OnLButtonUp怎么成了双击才触发????
- 在网上搜资源搜到csdn,点下载要登陆,登陆又不跳回去,再打开还要登陆,从csdn里搜又搜不到
- 请问CDialogBar加入sdi后,上面的按钮是disable的,为仕么?应该怎么改才能变成enable
- 请教datagrid控件在sdk中的应用!!
- 请帮忙做一个题: 当按下Ctrl+A时,要求显示"Ctrl + A".要求用SDK做.谢谢!
- 我下载的Xtreme9.61怎么编译不通过?
- 如何在mfc源码中设断点调试?
- 求CString类的所有方法原型,功能
- 高分求救!视频采集问题!
- msdn里关于windows用户管理的api在哪一章节
- 传递消息问题
- 海量数据处理问题
pProcConnGSM是__stdcall的么。?
你的DLL函数默认是__stdcall,因此在调用DLL的时候声明函数原型,一定要使用__stdcall。
一、声明为extern "C"的话,就是以C的语法规定吧
我看有几个变量声明不在开始,而在中间部分二、函数声明为私有导出函数
换成绝对路径试试
g_hGMSDLL = LoadLibrary("..\\bin\\SMS.dll"); pProcConnGSM = (Sms_Connection)GetProcAddress(g_hGMSDLL, "Sms_Connection");
两处调用都没有判断是否成功如果加载失败,调用肯定有问题
if(InitNoteInfo())
{...}
else
{...}
我改成了
if(1 == InitNoteInfo())
{...}
else
{...}
然后错误就没了,但是我就不明白为什么了,能给个理由吗?
#define STDINTMETHOD extern "C" int __stdcall
// all interface method of this library provide listSTDINTMETHOD InitNoteInfo(int);
#define STDINTMETHOD // ??? 这是什么意思?上面定义的内容又被取消了?
哦,那个如果谁知道为什么会出现这种情况,就是加个 1 == 后就没错了,如果谁知的话,回一下我哈,谢谢了,邮箱是[email protected]