- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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?
- Balises:
- Intel® Fortran Compiler
Lien copié
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
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.
- Marquer comme nouveau
- Marquer
- S'abonner
- Sourdine
- S'abonner au fil RSS
- Surligner
- Imprimer
- Signaler un contenu inapproprié
- S'abonner au fil RSS
- Marquer le sujet comme nouveau
- Marquer le sujet comme lu
- Placer ce Sujet en tête de liste pour l'utilisateur actuel
- Marquer
- S'abonner
- Page imprimable