Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;从dll调用FORTRAN子例程 我必须处理一些非常古老的FORTRAN代码,但是我想使用C++中FORTRAN中的一些函数。现在我有一个小项目,用Fortran DLL导出并导入C。我在Windows上用FTNRAN和Fortran C++的FTN95编译器进行。我的fortran源代码包含以下函数: F_STDCALL integer function test_fort(a) implicit none integer, intent(in) :: a test_fort = 2*a end function < >我将它编译成Ford.dl,然后将其放入C++项目的输出文件夹中。 C++源代码: #include<stdlib.h> #include<Windows.h> #include<stdio.h> typedef int(__stdcall *test_fort)(int* a); int main() { HMODULE hFortDll = LoadLibraryW(L"FORT.dll"); if (hFortDll == NULL) wprintf(L"Error loading FORT.dll"); else { wprintf(L"Loading successful\r\n"); FARPROC result = GetProcAddress(hFortDll, "test_fort"); test_fort fortSubroutine = (test_fort)result; if (fortSubroutine == NULL) wprintf(L"Function not found\r\n"); else wprintf(L"Function successfully loaded\r\n"); FreeLibrary(hFortDll); } getchar(); return 0; }_C++_C_Dll_Fortran - Fatal编程技术网

C++;从dll调用FORTRAN子例程 我必须处理一些非常古老的FORTRAN代码,但是我想使用C++中FORTRAN中的一些函数。现在我有一个小项目,用Fortran DLL导出并导入C。我在Windows上用FTNRAN和Fortran C++的FTN95编译器进行。我的fortran源代码包含以下函数: F_STDCALL integer function test_fort(a) implicit none integer, intent(in) :: a test_fort = 2*a end function < >我将它编译成Ford.dl,然后将其放入C++项目的输出文件夹中。 C++源代码: #include<stdlib.h> #include<Windows.h> #include<stdio.h> typedef int(__stdcall *test_fort)(int* a); int main() { HMODULE hFortDll = LoadLibraryW(L"FORT.dll"); if (hFortDll == NULL) wprintf(L"Error loading FORT.dll"); else { wprintf(L"Loading successful\r\n"); FARPROC result = GetProcAddress(hFortDll, "test_fort"); test_fort fortSubroutine = (test_fort)result; if (fortSubroutine == NULL) wprintf(L"Function not found\r\n"); else wprintf(L"Function successfully loaded\r\n"); FreeLibrary(hFortDll); } getchar(); return 0; }

C++;从dll调用FORTRAN子例程 我必须处理一些非常古老的FORTRAN代码,但是我想使用C++中FORTRAN中的一些函数。现在我有一个小项目,用Fortran DLL导出并导入C。我在Windows上用FTNRAN和Fortran C++的FTN95编译器进行。我的fortran源代码包含以下函数: F_STDCALL integer function test_fort(a) implicit none integer, intent(in) :: a test_fort = 2*a end function < >我将它编译成Ford.dl,然后将其放入C++项目的输出文件夹中。 C++源代码: #include<stdlib.h> #include<Windows.h> #include<stdio.h> typedef int(__stdcall *test_fort)(int* a); int main() { HMODULE hFortDll = LoadLibraryW(L"FORT.dll"); if (hFortDll == NULL) wprintf(L"Error loading FORT.dll"); else { wprintf(L"Loading successful\r\n"); FARPROC result = GetProcAddress(hFortDll, "test_fort"); test_fort fortSubroutine = (test_fort)result; if (fortSubroutine == NULL) wprintf(L"Function not found\r\n"); else wprintf(L"Function successfully loaded\r\n"); FreeLibrary(hFortDll); } getchar(); return 0; },c++,c,dll,fortran,C++,C,Dll,Fortran,调试器显示结果包含零地址(0x00000000)。我不知道我做错了什么,像这样的帖子也没有提供答案 提前感谢。由于响应速度非常快,并且链接到一个非常有用的工具,我发现问题出在函数名上。虽然我花了一些时间更改了“test_-fort”的大小写,并在其中添加了“_”之类的符号,但我错过了“test_-fort”变体-这是.dll中“test_-fort”FORTRAN函数的别名。 因此,为了让它工作,我只需更改一行代码: FARPROC result = GetProcAddress(hFortDl

调试器显示结果包含零地址(0x00000000)。我不知道我做错了什么,像这样的帖子也没有提供答案


提前感谢。

由于响应速度非常快,并且链接到一个非常有用的工具,我发现问题出在函数名上。虽然我花了一些时间更改了“test_-fort”的大小写,并在其中添加了“_”之类的符号,但我错过了“test_-fort”变体-这是.dll中“test_-fort”FORTRAN函数的别名。 因此,为了让它工作,我只需更改一行代码:

FARPROC result = GetProcAddress(hFortDll, "TEST_FORT");

使用depends()找出fortran例程的实际调用内容。它可能有前导下划线或尾随下划线,或者可能完全是大写。另外,请注意您使用的是Unicode-Fortran通常是ASCII格式的。我知道我使用的是Unicode。但是,正如我所理解的,库加载可以使用Unicode,并且GetProcAddress的第二个参数的类型是LPCSTR,而不是LPCWSTR。所以应该没问题,但我会检查的
FARPROC result = GetProcAddress(hFortDll, "TEST_FORT");