- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am trying to call a function in C++ Dll module and passing two character variables. It works fine with one variable but when the second is added I get an error "Stack trace terminated abonormally". My fortran code is as follows:
INTERFACE
integer function GetRandomChar(char1, char2)
!DEC$ ATTRIBUTES C,DLLIMPORT
!DEC$ ATTRIBUTES ALIAS:'_GetRandomChar'::GetRandomChar
!DEC$ ATTRIBUTES REFERENCE :: char1, char2
character*(*) :: char1, char2
end function GetRandomChar
end interface
tmpchar1 = 'text1' //char(0)
tmpchar2 = 'text2'//char(0)
tmpCharid = GetRandomChar(tmpchar1, tmpchar2)
The C++ Dll code is as follows:
In header file:
extern "C" __declspec(dllexport) int GetRandomChar(char*, char*);
In CPP file:
extern "C" __declspec(dllexport) int GetRandomChar(char *test5, char *test6)
{
ofstream myfile("AAA.txt");
//myfile.open ("C:\\\\work\\\\AAA.txt");
myfile << "Writing this to a file.\\n";
myfile << test5;
myfile << "\\n";
myfile << test6;
myfile.close();
}When I try to access the test6 I get the error. If I comment out "myfile << test6" it runs without problems. What could be wrong?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I modified your code enough to make it compile and link, and I did not see the same error.
F:\tests>type aaa.txt
Writing this to a file.
text1
text2
As written in this note, the attributes on the interface declaration to GetRandomChar do not compile. Please make sure that the real code is correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page