0
votes

I have c++ dll project and at this, I have a typedef declaration like this

typedef void* ScreenNode;

and in my header file i use this deceleration

extern "C" __declspec(dllexport) int CB_AddProgramColor (ScreenNode g_screen_node,ProgramNode program_node,int color, int alpha);

Now, I wand to use this function in C# with a class like this

internal unsafe partial class BBIA
{
[DllImport(dllName)]
        public static extern
            int CB_initNode(ScreenNode g_screen_node, int width, int heigth,EN_DevType EN_C1Dev);
}

but I take error on ScreenNode g_screen_node with this detail.

"Error 1 The type or namespace name 'ScreenNode' could not be found (are you missing a using directive or an assembly reference?)"

I have 2 question:

  1. I have to declare typedef void* ScreenNode in C# Project?
  2. My typedef is in void data type. what can i do for this declaration in C#?
1
The closest thing in C# to typedef is the aliased 'using' applied to types: e.g., "using Foo = System.Datetime;", which would allow you to specify 'Foo' instead of 'Datetime' in that file (doesn't help for your example however). Like the 'typedef' in C++, this doesn't always enhance code clarity. - Dave Doknjas

1 Answers

0
votes

C# does not have typedef, so you have to specify type (not alias) in all places where you use it. For C++ void* you can use void* or IntPtr in C#.