Hi Richard,
Based on the error message System.BadImage FormatException , the application
needs a qualified image to load the static method of
CPPFu.CPPClass. FirstFu(); but you don't provide an assembly corresponds to
it, so this would be the reason to get that exception.
On this point, I suggest you build an assembly to provide the function
CPPFu.CPPClass. FirstFu(), you can use the AL.exe to generate the required
assembly from its .netmodule.
Since I cannot build your csuse.cs and macpp.cpp due to the interlock
reference issue, I extract the CPPFu.CPPClass definition to a stand-alone
cpp source file, and build an assembly from it for the use of csuse.cs.
Please refer to the following sample code:
//cppfu.cpp
#include <stdio.h>
namespace CPPFu
{
public __gc class CPPClass{ // ref was __gc.
public: static void FirstFu(void)
{
printf("In FirstFu\n");
}
};
}
//MACPP.cpp
#include <stdio.h> // 20050303 for printf.
#include <malloc.h>
// 20060121 Cpp program with main to be called by CS.
// This program to be compiled with /clr:oldsyntax.
#using <CSUse.netmodul e>
void CppFun01(void)
{
printf("CppFun0 1\n");
}
extern "C"{
// in manc.cpp, called by cmain.c
// Duplicate prototypes are in cmain.c.
void mainfu(void);
}
void mainfu(void)
{
printf("In CPP Main\n");
CppFun01();
NSinCS::CSFun:: CSFun01();
NSinCS::CSFun:: CSFun02();
}
//MAKE.bat
cl /LN /clr: oldsyntax cppfu.cpp
al cppfu.netmodule /platform:x86 /target:lib /out:cppfu.dll
csc /t:module /r:cppfu.dll csuse.cs
cl /LN /clr:oldsyntax macpp.cpp
cl cmain.c macpp.obj /link /nodefaultlib:li bcmt
By the way, if you can build your csuse.cs and macpp.cpp module without the
interlock problem, maybe you don't need to split the CPPFu.CPPClass
definition from the macpp.cpp file, in this scenario, you need to build an
assembly from the macpp.netmodule and reference it when building the
csuse.netmodule :
¡*
al macpp.netmodule /platform:x86 /target:lib /out:macpp.dll
csc /t:module /r:macpp.dll csuse.cs
¡*
Wish it helps!
Thanks for your understanding!
Best regards,
Gary Chang
Microsoft Community Support
--------------------
Get Secure! ¡§C
www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://support.microsoft.com/default...sdn/nospam.asp
&SD=msdn
This posting is provided "AS IS" with no warranties, and confers no rights.