Use C++ code in C# code

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
WGT_4383351
Level 5
Level 5
First like received

How to add C++ data xfer into existing C# code?

For example, existing C# code is:

outEndpoint.XferData(ref buf, ref len, true);

But use C# to load/process data before sending them is slow.

What is needed is a C++ method to be called through P/Invoke to do the data load and send job.

The problem is how to get the C++ CCyUSBEndPoint corresponding to the C# outEndpoint? What handle to pass to the C++ P/invoke method?

The C++ examples looks strange, are they C++/CLI code?

0 Likes
1 Solution
YatheeshD_36
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello,

The C++ CyAPI.lib is a static library and P/Invoke is used to import a .dll dynamic link unmanaged library into your managed code.

We have not used CyAPI.lib in C# before as we have two different completely functional library for the two programming languages.

Please refer to this link which may be of help: https://stackoverflow.com/questions/2958416/call-c-library-from-c-sharp

Thanks,

Yatheesh

View solution in original post

0 Likes
1 Reply
YatheeshD_36
Moderator
Moderator
Moderator
750 replies posted 500 replies posted 250 solutions authored

Hello,

The C++ CyAPI.lib is a static library and P/Invoke is used to import a .dll dynamic link unmanaged library into your managed code.

We have not used CyAPI.lib in C# before as we have two different completely functional library for the two programming languages.

Please refer to this link which may be of help: https://stackoverflow.com/questions/2958416/call-c-library-from-c-sharp

Thanks,

Yatheesh

0 Likes