麻烦在WinCE5 API调用中将字符串传递给lpctstr

时间:2015-12-03 17:25:24

标签: vb.net visual-studio-2008 windows-ce smart-device

我正在尝试使用以下命令调用VS2008智能设备项目中的Windows CE 5 API调用“FindFirstChangeNotification”:

Private Declare Function FindFirstChangeNotification Lib "coredll.dll" _
(ByVal lpPathName As String, ByVal bWatchSubtree As Long, _
ByVal dwNotifyFilter As Long) As Long

Dim strFolderPath As String = "\My Documents\My App Files\"
Dim ptrHandle as IntPtr = FindFirstChangeNotification(strFolderPath, 0, 1)

尝试此方法会导致“System.NotSupportedException”,我认为这是字符串类型的不兼容。尽管尝试了不同的编组行为,但几天之后我仍然陷入困境。

1 个答案:

答案 0 :(得分:1)

Windows CE中的字符串类型是Unicode,因此声明为String应该是正确的。

Coredll实际上将该功能导出为FindFirstChangeNotificationW(请注意尾随' W'),这可能是您获得例外的原因。

' W'表示宽函数,如宽字符或Unicode,函数的实现。通常,您可以在Visual Studio命令提示符中使用dumpbin工具来标识函数导出的名称,在这种情况下,我使用dumpbin /exports coredll.dll进行检查。

另据我所知,在VB.Net中Long是64位类型,FindFirstChangeNotification需要32位参数。

所以试试这个:

Private Declare Function FindFirstChangeNotificationW Lib "coredll.dll" _
(ByVal lpPathName As String, ByVal bWatchSubtree As Integer, _
ByVal dwNotifyFilter As Integer) As Integer
相关问题