跟调用API函数一样: [DllImport("user32.dll",CharSet="CharSet.Auto",EntryPoint="MessageBox")] public static extern int MsgBox(IntPtr hWnd,string txt,string caption, int type);如果是com的话引用一下就行了
C++代码: BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved ) { return TRUE; } int IntTest(int* a,int* b) { return *a + *b; } C#代码: class MyClass { [DllImport("StandardDll.dll",CharSet=CharSet.Auto,EntryPoint="IntTest")] static extern int Test(ref int a,ref int b); public static void Main() { int a = 10; int b = 2; int c = Test(ref a,ref b); Console.WriteLine(c); } }
找不到类型或命名空间名称“DllImport”(是否缺少 using 指令或程序集引用?)请问这个问题如何解决阿? 还有6.0的dll是否要在解决方案中引用?
[DllImport("user32.dll",CharSet="CharSet.Auto",EntryPoint="MessageBox")]
public static extern int MsgBox(IntPtr hWnd,string txt,string caption, int type);如果是com的话引用一下就行了
BOOL APIENTRY DllMain( HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved )
{
return TRUE;
}
int IntTest(int* a,int* b)
{
return *a + *b;
}
C#代码:
class MyClass
{
[DllImport("StandardDll.dll",CharSet=CharSet.Auto,EntryPoint="IntTest")]
static extern int Test(ref int a,ref int b);
public static void Main()
{
int a = 10;
int b = 2;
int c = Test(ref a,ref b);
Console.WriteLine(c);
}
}
还有6.0的dll是否要在解决方案中引用?
但是依然不知6.0的dll应该放在.Net解决方案目录中的什么位置,请告知!