Reputation: 651
I don't have a lot of experience on UWP programming and i built an app does some stuff on Bluetooth. Now i have to cary some info through APIs. But somehow "SendMessage" doesnt work. Here is the code i'm using
public static class ApiComm
{
[DllImport("User32.dll")]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int uMsg, int wParam, int lParam);
public static string DelphiFormClassName = "TFrmMain";//"wsdk_delphi_api_test";
public static string DelphiFormCaptionName = "Deneme";
private static IntPtr FindDelphiForm(string delphiFormClassName, string delphiFormCaptionName)
{
return FindWindow(delphiFormClassName, delphiFormCaptionName);
}
private static IntPtr FindDelphiForm()
{
return FindDelphiForm(DelphiFormClassName, DelphiFormCaptionName);
}
public static int TextToID(string text)
{
int mu = (text == null ? 0 : text.Length);
int result = 0;
for (int i = 0; i < mu; i++)
result = result + (((i + 1) * 256) + (byte)(text[i]));
return result;
}
private const int WM_COMMAND = 0x0111;
private const int StartFrom = 500;
private static int EventID(RemoteDeviceUpdate anEvent)
{
return StartFrom + (int)anEvent;
}
public static void SendInfo(int remoteID, RemoteDeviceUpdate anEvent)
{
IntPtr wP = FindDelphiForm();
if (wP != null && wP != IntPtr.Zero)
{
int eID = EventID(anEvent);
SendMessage(wP, WM_COMMAND, eID, remoteID);
}
}
public static void SendInfo(string remoteID, RemoteDeviceUpdate anEvent)
{
SendInfo(TextToID(remoteID), anEvent);
}
}
when i try SendInfo with another .net projects, it works just fine but with UWP it doesnt (and it doesnt give any error also)
do i have to add packages or something to my project..
any help would be appreciated, thanks.
Upvotes: 0
Views: 716
Reputation: 32775
Derive from this case, you need check if the API available to Windows Runtime apps.
Apps can p-invoke DLLs deployed with the app package. The DLL will run in the app's context and have the same API access as the app itself. See Win32 and COM APIs for an overview of Win32 API available to Windows Runtime apps.
If you just want to build an app does some stuff on Bluetooth. You can do it all with uwp
Bluetooth api. And this is official document. For RFFCOMM
, this is uwp code sample that you could refer.
Upvotes: 1