Hy all,DllImport C Sharp const char *
我想從一個非託管dll到C#託管的dll。
文檔中是:
typedef void* AP_HANDLE
typedef uint32_t ap_u32
AP_HANDLE ap_CreateVirtual(const char *szFilename)
void ap_SetState(AP_HANDLE apbase, const char *szState, int nValue)
unsigned char *ap_ColorPipe(AP_HANDLE apbase,
unsigned char *pInBuffer,
ap_u32 nInBufferSize,
ap_u32 *rgbWidth,
ap_u32 *rgbHeight,
ap_u32 *rgbBitDepth)
在C++中工作正常,但在C#語法看來我不能讓不埃文第一功能工作
public unsafe class appbase
{
[DllImport("D:\\apbase.dll", EntryPoint = "ap_CreateVirtual")]
//, CharSet = UnicodeEncoding
//, CallingConvention = CallingConvention.StdCall
public static extern void* ap_CreateVirtual(char* szFilename);
}
問題
和
public static void Main()
{
unsafe
{
void* ap_handle = null;
appbase APPbase = new appbase();
string s = "D:\\ASX.xsdat";
fixed (char* p = s)
{
ap_handle = APPbase.ap_CreateVirtual(p);
}
return;
}
}
嘗試使用ap_CreateVirtual字符串的參數,String *,ch ar *,char []並在返回時放置一個斷點; ap_handle始終爲值0x0000
什麼是導入這些函數的正確方法?
你需要讀取P/Invoke –