在DLL提供的.h文件中,关键代码:# define TTSLIBAPI __declspec(dllimport)TTSRETVAL TTSLIBAPI TTSInitializeEx(const char* pszEngine, void* pvReserved);
typedef TTSRETVAL (*Proc_TTSInitializeEx)(const char* pszEngine, void* pvReserved);
DLL加载代码:
.h
#define STTSWINAPI WINAPI
extern TTSRETVAL (STTSWINAPI *STTSInitializeEx)(const char* pszEngine, void* pvReserved);.cpp
TTSRETVAL (STTSWINAPI *STTSInitializeEx)(const char* pszEngine, void* pvReserved);
BOOL STTSLoadLibrary()
{
DWORD dwErr; hSTTSApiMod=LoadLibrary(_T("iFlyTTS.dll"));
if(hSTTSApiMod==NULL) {
dwErr=GetLastError();
SetLastError(dwErr);
bSTTSApiLoaded = FALSE;
return bSTTSApiLoaded;
} STTSInitializeEx = (TTSRETVAL (STTSWINAPI *)(const char*, void*))GetProcAddress(hSTTSApiMod,"TTSInitializeEx");
}结果在执行过程中
if(!STTSLoadLibrary())
{
return FALSE;
}
if(STTSInitializeEx(NULL, NULL) != TTSERR_OK) ///这里报错。错误框内容:“Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. ”
说是调用类型不一致? 该怎么改呢?而且提示错误的时候,我一直按继续,结果就执行成功了。
typedef TTSRETVAL (*Proc_TTSInitializeEx)(const char* pszEngine, void* pvReserved);
DLL加载代码:
.h
#define STTSWINAPI WINAPI
extern TTSRETVAL (STTSWINAPI *STTSInitializeEx)(const char* pszEngine, void* pvReserved);.cpp
TTSRETVAL (STTSWINAPI *STTSInitializeEx)(const char* pszEngine, void* pvReserved);
BOOL STTSLoadLibrary()
{
DWORD dwErr; hSTTSApiMod=LoadLibrary(_T("iFlyTTS.dll"));
if(hSTTSApiMod==NULL) {
dwErr=GetLastError();
SetLastError(dwErr);
bSTTSApiLoaded = FALSE;
return bSTTSApiLoaded;
} STTSInitializeEx = (TTSRETVAL (STTSWINAPI *)(const char*, void*))GetProcAddress(hSTTSApiMod,"TTSInitializeEx");
}结果在执行过程中
if(!STTSLoadLibrary())
{
return FALSE;
}
if(STTSInitializeEx(NULL, NULL) != TTSERR_OK) ///这里报错。错误框内容:“Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention. ”
说是调用类型不一致? 该怎么改呢?而且提示错误的时候,我一直按继续,结果就执行成功了。
咋整?
本来是 __cdecl
我改了__fastcall和__stdcall 结果还都同样的提示。
#define STTSWINAPI WINAPI
将接口定义成了 WINAPI 也就是 __stdcall 了,需要如下修改:#define STTSWINAPI __cdecl应该就可以了。