Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a c++ project with a method
C++
int recvPDU(mmslib::MMSpdu_PDU* pdu, mmslib::mms_Control* ctl);
which has user defined input parameters.

I wish to use this method in a c# project by creating a dll of the method recvPDU. I have successfully created the dll. But I cannot understand how to use the dllimport.

What I have tried:

The C# code is as:


C#
[DllImport(@"C:\\Riddhi_GIT\\IEC 61850 Lib\\Debug\\Prototype_IECServer.dll")]
       
 private static extern int recvPDU(... pdu, ... ctl);


The path to the dll is right. But I need help to put the datatype instead of ... in the dllimport.
Posted
Comments
Richard MacCutchan 8-Jan-18 7:02am    
Since both parameters are pointers you can use the IntPtr type. You will also need to create a structure mapping for each parameter: StructLayoutAttribute Class (System.Runtime.InteropServices)[^].
Member 13612015 12-Jan-18 7:28am    
Thank you for your reply. I am new to c++. I have never worked on it. Plus the code I am using is written by someone else. I dont know how to create structure mapping. Can you show me an example?
Richard MacCutchan 12-Jan-18 9:07am    
The example is in the link I provided above.
Member 13612015 12-Jan-18 9:22am    
Ya. I understood it later. Thanks a lot

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900