Including .dll in /clr:pure project [VC++ '05]
-
Hello, Is it possible to include a .dll in a /clr:pure project? I am currently using unmanaged code for this. I was wondering if it is also possible with a /clr:pure project which does not allow native C++? Including a .dll can be done with C#. (Full setting is "Pure MSIL Common Language Runtime Support (/clr:pure)" in the project properties -> General) best regards, Jan Timmerman
-
Hello, Is it possible to include a .dll in a /clr:pure project? I am currently using unmanaged code for this. I was wondering if it is also possible with a /clr:pure project which does not allow native C++? Including a .dll can be done with C#. (Full setting is "Pure MSIL Common Language Runtime Support (/clr:pure)" in the project properties -> General) best regards, Jan Timmerman
What do you mean by 'include a dll'? If ur question is whether an unmanaged dll can be used in a
/clr:pure
c++/cli project, Yes, You can do. Inlcude the lib and header file to c++/cli project and you can create objects of unmanaged clasees in the dll or u can call unmanaged functions in that dll. You can use a com dll as well using the#import
c++/cli is the only language where u can mix both managed unmanaged code. deoes this make sense...mil10. -
What do you mean by 'include a dll'? If ur question is whether an unmanaged dll can be used in a
/clr:pure
c++/cli project, Yes, You can do. Inlcude the lib and header file to c++/cli project and you can create objects of unmanaged clasees in the dll or u can call unmanaged functions in that dll. You can use a com dll as well using the#import
c++/cli is the only language where u can mix both managed unmanaged code. deoes this make sense...mil10.Thanks for your reply: Well that was about where I was aiming at. I never heard of the "#import" directive before so I will have to look into that. I have not too much experience with Visual studio. Perhaps I should explain a little more about the situation. Currently I have a ".lib" and a ".dll" generated by Compaq Visual Fortran. I've declared the function called from the .dll as follows:
extern "C" void __declspec(dllimport) extiteratie( [arguments] )
First I get the warning:TFortranInterface.cpp(27) : warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function.
after that an errorerror LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata
(After this an unresolved token error which is most likely caused by the previous error.) I am currently using a native class as interface because I need to pass the function in the .dll a set of pointers which will be filled with results. The questions: 1. With /clr:pure I cannot use that native class? 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) (3. what does #import do?) best regards, Jan Timmerman -
Thanks for your reply: Well that was about where I was aiming at. I never heard of the "#import" directive before so I will have to look into that. I have not too much experience with Visual studio. Perhaps I should explain a little more about the situation. Currently I have a ".lib" and a ".dll" generated by Compaq Visual Fortran. I've declared the function called from the .dll as follows:
extern "C" void __declspec(dllimport) extiteratie( [arguments] )
First I get the warning:TFortranInterface.cpp(27) : warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify native calling convention when importing a function.
after that an errorerror LNK2031: unable to generate p/invoke for "extern "C" void __clrcall extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata
(After this an unresolved token error which is most likely caused by the previous error.) I am currently using a native class as interface because I need to pass the function in the .dll a set of pointers which will be filled with results. The questions: 1. With /clr:pure I cannot use that native class? 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) (3. what does #import do?) best regards, Jan Timmerman1. With /clr:pure I cannot use that native class? Yes, You can use native class in a /clr:pure c++/cli project. 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) Note the warning you got:
"warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify **native calling convention** when importing a function."
Your function declaration was:extern "C" void __declspec(dllimport) extiteratie( [arguments] )
: Here you havn't mentioned any calling convention. So compiler took the clr only calling convention__clrcall
. Now see the error message you got - "error LNK2031: unable to generate p/invoke for "extern "C" void__clrcall
extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata" This means that C++/CLI compiler is not able to generate the p/invoke for a function which is reserverd for CLI only (because of the by default__clrcall
calling convention). So to fix this, change the function declaration as below:extern "C" void __stdcall __declspec(dllimport) extiteratie( [arguments] )
Here if the calling convention of extiteratie is soemthing else other than__stdcall
, then put the same instaed. 3. what does #import do?) You dont have to worry abt #import as ur dll is not a com dll. It is for using com components. Hope this will help...mil10. -
1. With /clr:pure I cannot use that native class? Yes, You can use native class in a /clr:pure c++/cli project. 2. Any idea what the error could mean (and/or perhaps an alternate declaration for the function in the .dll?) Note the warning you got:
"warning C4272: 'extiteratie' : is marked __declspec(dllimport); must specify **native calling convention** when importing a function."
Your function declaration was:extern "C" void __declspec(dllimport) extiteratie( [arguments] )
: Here you havn't mentioned any calling convention. So compiler took the clr only calling convention__clrcall
. Now see the error message you got - "error LNK2031: unable to generate p/invoke for "extern "C" void__clrcall
extiteratie( float*, float*, (...) float* )" (?extiteratie@@$$J0YMXPAM000000000000000PAH110@Z); calling convention missing in metadata" This means that C++/CLI compiler is not able to generate the p/invoke for a function which is reserverd for CLI only (because of the by default__clrcall
calling convention). So to fix this, change the function declaration as below:extern "C" void __stdcall __declspec(dllimport) extiteratie( [arguments] )
Here if the calling convention of extiteratie is soemthing else other than__stdcall
, then put the same instaed. 3. what does #import do?) You dont have to worry abt #import as ur dll is not a com dll. It is for using com components. Hope this will help...mil10.Great, it works! i've modified the function call to
extern "C" void __cdecl extiteratie( [arguments] )
(from the error messages I noticed the compiler ignores the "__declspec(dllimport)" part when including __cdecl) Also I added an underscore to the function export in the Fortran code which was needed by __cdecl. An alternative is (most likely but not tested) to use __stdcall in the export. I do not think it makes much difference whether I use __stdcall or __cdecl? Thanks a lot! Jan Timmerman