Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6030381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:01:43+00:00 2026-05-23T05:01:43+00:00

I have a DLL and its header file, which were written in Visual C++.

  • 0

I have a DLL and its header file, which were written in Visual C++. I need to use the following function in a C# project:

LIBSPEC int
CprFindDevices(
  PCprDeviceInfo *ppDevInfo,
  int *pNumDevices,
  DWORD timeout
  );

I am able to import it with a DllImport, but I cannot figure out how to implement the following structure in C#:

typedef struct _CprDeviceInfo
{
  unsigned char id[ID_LEN];
  unsigned char macAddr[MAC_LEN];
  in_addr       inAddr;
  char          ipAddr[IP_LEN];
  char          devName[INFO_NAME_LEN];
  char          port1Name[INFO_NAME_LEN];
  char          port2Name[INFO_NAME_LEN];
  int           tcpPort1;
  int           tcpPort2;
  char          interfaceIpAddr[IP_LEN];
} CprDeviceInfo, *PCprDeviceInfo;

The all-upper-case variables are all known constants which I can use in my C# project.

I know I must use [StructLayout(LayoutKind.Sequential)], but am not sure what the equivalent types are for each of the structure’s members, and what the function signature would be when I import it. It’s been a while since my C++ days.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:01:43+00:00Added an answer on May 23, 2026 at 5:01 am

    This should do the job for you:

    struct CprDeviceInfo
    {
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = ID_LEN)]
        string id;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = MAC_LEN)]
        string macAddr;
        uint inAddr;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IP_LEN)]
        string ipAddr;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = INFO_NAME_LEN)]
        string devName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = INFO_NAME_LEN)]
        string port1Name;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = INFO_NAME_LEN)]
        string port2Name;
        int tcpPort1;
        int tcpPort2;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = IP_LEN)]
        string interfaceIpAddr;
    }
    

    Make sure you are using Charset.ASCII in your DLLImport which is the default.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dll that was written in c++, I need to use this
I have the following C Header/Code Example: Header file struct category_info { int id;
I have an DLL that has this in its h file: extern C __declspec(dllexport)
I have a .NET dll which needs to read it's config settings from it's
I have the .def file, .lib file, the .dll, the source files. It's using
I have DLL and application that will call some function in this dll. For
I have a DLL in the BIN folder, and I need it to be
I have been working on getting a basic ATL project to compile in Visual
I have a DLL with one single function That gets five doubles and one
I'm working on something which dynamically loads specially formulated DLL's. I need to be

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.