我得到了一個project.dll和頭文件。它的定義是這樣的:在C中使用C dll中定義的typedef函數#
#ifdef PPSDK_EXPORTS
#define PP_SDK_API __declspec(dllexport)
#else
#define PP_SDK_API __declspec(dllimport)
#endif
#ifndef __PP_SDK__
#define __PP_SDK__
typedef enum
{
PP_FALSE= 0x0,
PP_TRUE = 0x01
} pp_bool;
PP_SDK_API pp_bool SDK_Initialize(unsigned long*p_Status);
我使用一些幫助谷歌和本網站使用此DLL在C#中,但沒有成功。 pp_bool類型錯誤。 這是我的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
[DllImport("project.dll")]
static extern pp_bool SDK_Initialize(unsigned long*p_Status);
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
..................................... 你能幫我怎麼處理它。 謝謝!
您需要確定pp_bool'的'類型。既然它是一個'enum',編譯器就可以使用它想要的任何整數類型,只要該類型可以適合所有的值(並且不大於int除非它必須是) - 所以它可能是bool, short,int,char等等。你需要輸出'sizeof(pp_bool)'來找出你的特定編譯器正在使用什麼類型,然後將它與C#中等價的整數類型進行匹配。另外,在C#端'unsigned long *'應該是'ref uint'(假設C代碼中有32位長)。 – Cameron