步驟來創建使用C++爲Windows Mobile的DLL:
1)文件>新建>項目...>的Visual C++>智能設備> Win32的智能設備項目
2)寫的名字該項目並單擊確定。
3)下一步>插入需要
4)右鍵點擊Source文件夾的SDK(如WM5和WM6)>下一頁>點擊DLL>完成,然後選擇添加>新
5)查找.DEF文件名稱與dll名稱相同,然後單擊確定。
現在高清你需要寫這樣的事:
LIBRARY "dllName"
EXPORTS
exactFunctionName1 DATA
exactFunctionName2 DATA
In dllName.cpp You need to add those two methods (exactFunctionName1, exactFunctionName2) and write code for them.
You don't need to state more then a method names in def (plus <tab><tab>DATA next to name).
Where to place the DLL after builiding to make use of it in my C# project
It must be placed next to Your app or in Windows folder of Your device.
To get methods from that library just do the following in C#:
using System.Runtime.InteropServices;
[DllImport("dllName.dll")]
private static extern anyReturnType exactFunctionName1(anyArgumentType argumentName);
So as an example let's get arithmethic sum form myMath.dll:
[DllImport("myMath.dll")]
private static extern int sum(int first, int second);
Those methods can be also public but they still require "static extern".
Following example in C++ side You'll have this:
In myMath.cpp:
INT sum(INT first, INT second)
{
return first + second;
}
In myMath.def:
LIBRARY "myMath"
EXPORTS
sum DATA
來源:
http://social.msdn.microsoft.com/Forums/en-US/windowsmobiledev/thread/98e60ab6-aecf-4399-a5be-4937ec40aac9
桌面不需要安裝CF消耗CF組件。 CF組件可重定位並在完整框架下運行。 – ctacke 2009-11-25 16:16:46
謝謝ctacke。 – EKS 2009-11-26 09:05:24