【发布时间】:2016-06-13 12:00:51
【问题描述】:
我正在尝试在 wisual studio 环境中调用 cygwin 编译的 dll。
如果我编译具有没有任何库的函数的 dll(只返回任何数字), 它工作正常,但如果我调用例如 stdio.h,并且写入文件的函数或只是 printf 函数,则不起作用(如果 printf 函数已退出代码 1536)。
#include <stdio.h>
int myfunc()
{
char* strtxt = "test";
FILE *hF = fopen( "Newlogtst.txt", "w" );
if(hF == 0)
{
return 5;
}
fputs( (const char*)strtxt, hF );
fclose(hF);
return 1;
}
int tst()
{
return 25;
}
function tst 工作正常,function myfunc 生成空文件Newlogtst.txt 并显示异常。
`
在 CygwinDlltest.exe 中的 0x6113333A (cygwin1.dll) 处引发异常: 0xC0000005:访问冲突读取位置0x004E0059。
如果有这个异常的处理程序,程序可能是安全的 继续。
` 在 Visual Studio 中,我正在使用此代码
#include <windows.h>
typedef int (*PFN_HELLO)();
typedef void (*PFN_CYGWIN_DLL_INIT)();
int main()
{
PFN_HELLO func;
HMODULE hLib, h = LoadLibrary(TEXT("C:\\cygwin\\bin\\cygwin1.dll"));
PFN_CYGWIN_DLL_INIT init = (PFN_CYGWIN_DLL_INIT) GetProcAddress(h,"cygwin_dll_init");
init();
hLib = LoadLibrary (TEXT("C:\\Cygwin\\home\\azatyan\\TestDynamicLink\\mydll.dll"));
func = (PFN_HELLO) GetProcAddress (hLib, "myfunc");
return func();
}
请帮助我应该如何使用库函数。
【问题讨论】:
-
function
myfuncno...._你能详细说明一下吗? -
LPs:实际上它确实使
Newlogtst.txt文件为空,并退出并出现此异常-“在 CygwinDlltest.exe 中的 0x6113333A (cygwin1.dll) 处引发异常:0xC0000005:访问冲突读取位置 0x004E0059。如果有这个异常的处理程序,程序可以安全地继续。" -
cup:谢谢,提供链接,但我认为这无济于事,我不想更改 Visual Studio 中的包含头路径,我想要的只是加载 dll,调用函数..
标签: c++ c visual-studio cygwin