Create a C/C++ dll and call it from C#

G

greg

I used the same approach as the one described here:
http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx

The only catch is that the project which I am trying to compile into a
dll is half written in C and the other half in C++. What were the
developers thinking !?! I am using Visual Studio 2005 and to create
the dll, I ran New Project -> Win32 Project -> Application Settings ->
DLL (plus the additional option of exporting symbols). Then I declare
all the functions in the MyDll.h and also include the header file of
the original project in stdafx.h. After including the latter header in
the *.c and *.cpp files the following error was thrown:

"fatal error C1853: 'Debug\MyDll.pch' precompiled header file is from
a previous version of the compiler, or the precompiled header is C++
and you are using it from C (or vice versa)"

If I don't include stdafx.h in the *c and *cpp files the following
error is thrown:

"fatal error C1010: unexpected end of file while looking for
precompiled header. Did tou forget to add '#include "stdafx.h" to your
source'"?

Can anyone help me out? I would really appreciate your input?

Thanks,
Greg
 
B

Ben Voigt [C++ MVP]

greg said:
I used the same approach as the one described here:
http://blogs.msdn.com/jonathanswift/archive/2006/10/02/780637.aspx

The only catch is that the project which I am trying to compile into a
dll is half written in C and the other half in C++. What were the
developers thinking !?! I am using Visual Studio 2005 and to create
the dll, I ran New Project -> Win32 Project -> Application Settings ->
DLL (plus the additional option of exporting symbols). Then I declare
all the functions in the MyDll.h and also include the header file of
the original project in stdafx.h. After including the latter header in
the *.c and *.cpp files the following error was thrown:

"fatal error C1853: 'Debug\MyDll.pch' precompiled header file is from
a previous version of the compiler, or the precompiled header is C++
and you are using it from C (or vice versa)"

If I don't include stdafx.h in the *c and *cpp files the following
error is thrown:

"fatal error C1010: unexpected end of file while looking for
precompiled header. Did tou forget to add '#include "stdafx.h" to your
source'"?

Under Configuration Properties -> C/C++ -> Precompiled Headers you can
disable them. I would recommend doing so for at least the .c files.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top