Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Status Updates

View All Updates

- - - - -

import c++ dll - pass class parameter


  • Please log in to reply
1 reply to this topic

#1 enp


    CC Lurker

  • New Member
  • Pip
  • 3 posts

Posted 03 April 2012 - 08:55 AM

I need to call c++ fuctions from c#.
The unmanaged code declaration is:

class MyClass{
void* data;
int index;

void getData(MyClass &myclass);
void setData (MyClass myClass);

what shoud be the DllImport functions and class declaration?

Edited by Roger, 03 April 2012 - 11:32 PM.
added code tags

  • 0

#2 kernelcoder


    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 07 April 2012 - 10:18 PM

I think you can make your c++ code as follows...
typedef struct _MyStruct {
void* data;
int index;
}MyStruct, *PMyStruct;

void getData(PMyStruct arg);
void setData(PMyStruct arg);

Then in C#, you need to do like following...

struct MyStruct 
    IntPtr data;
    int index;

public static extern void getData(MyStruct data);

public static extern void setData(MyStruct data);

  • 0

Also tagged with one or more of these keywords: import

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download