using existsing C++ or C API in C#

P

pei_world

Basically, I want to write a application that open a Bluetooth channel to
communicate with my other Bluetooth device to form a tiny intranet. but by
default C# doesn't provide API to handle it. and I got some information
about how to virtually implement this task: first, using the Serial COM
ports that created by Bluetooth; second,using the C++ Bluetooth API and some
thing like [DLLImport "XXX.dll"].

I am new to window and C# programmings, so...
Does anyone have any idea how to do it or any information or sample code to
implement it?

thanks
 
J

Jim

I am learning the same thing myself right now, except I am
not using Bluetooth, but a third party voice card. I have
used DllImport successfully with a command window, but
when I port it over to a windows form it crashes, so I am
in the process of working on that now.

I hope this example helps.

[DllImport("PikaAPI.dll")]
unsafe public static extern int
PK_BOARD_SetEventHandler(uint TResourceHandle, void*
PK_VOID, EventHandlerCB EventHandler);

This is the DllImport statement for a function called
setEventHandler in the PikaAPI. all you do is define what
I like to call a function protocol as you would in c++ and
pass the correct data types down. Now, the default
character set is ANSI.

then to use this in your code just do this.

unsafe
{
EventHandlerCB EB = new
EventHandlerCB(EventHandler);
if
((PK_BOARD_SetEventHandler(0, (void*)5000, EB)) !=
PK_SUCCESS)
{
//Console.Write
("Could Not set Trunk Event Handler");
return false;
}
else
{
//Console.Write
("DSP Trunk Event Handler set \r\n");
}
}

Here are two good links
http://www.csharphelp.com/archives/archive63.html
http://www.csharphelp.com/archives/archive52.html

hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top