有C++ 代码
    
#define PROPERTY_MAX_LEN    128 // 属性字段最大长度   
typedef struct _T_DEVICE_PROPERTY  
{  
    TCHAR szProperty[PROPERTY_MAX_LEN];  
} T_DEVICE_PROPERTY;  INT WMI_DeviceQuery( INT iQueryType, T_DEVICE_PROPERTY *properties, INT iSize );  
 现在我将他编译成dll,需要供C#来调用。
我C#的 代码 (部分)//定义结构体
[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential, CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public struct T_DEVICE_P
{
    [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeCount = 128)]
    public string[] sp;
}
//引用
[DllImport("WMI_DeviceQuery.dll", CharSet = CharSet.Ansi, SetLastError = true)]
public static extern int WMI_DeviceQuery(int a, ref T_DEVICE_P b,int c);//调用
T_DEVICE_P tps = new T_DEVICE_P();
int sdfer2 = WMI_DeviceQuery(0,ref tps,20);这样调用有错误:“无法在DLL“WMI_DeviceQuery.dll”中找到名为“WMI_DeviceQuery”的入口点”
我想肯定是我类型转换没转好。。哪位懂的  求 指点!(代码里可能有错别字 ,可以忽略)C++C#

解决方案 »

  1.   

    有个软件叫depends.exe 可以看看那个dll输出的函数具体叫什么?
      

  2.   

    看了下  竟然没有 函数入口点。。- -求教,我的C++代码  就 两个文件 .h 和 .cpp
    我建的  项目类型 是 类库  就一个 函数 
    INT WMI_DeviceQuery( INT iQueryType, T_DEVICE_PROPERTY *properties, INT iSize )
    这个 编译出来怎么就 没有函数 入口点了呢?
      

  3.   

    C++部分
    extern "C"  __declspec(dllexport) INT WMI_DeviceQuery( INT iQueryType, T_DEVICE_PROPERTY *properties, INT iSize );  
      

  4.   


    #define EXPORT_DLL extern "C" __declspec(dllexport)#include "CSharp.h"  这个是我的文件名称EXPORT_DLL int add(int a,int b)
    {
        return a+b;
    }
      

  5.   

    http://msdn.microsoft.com/zh-cn/library/a90k134d%28v=VS.80%29.aspx