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 913833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T17:37:21+00:00 2026-05-15T17:37:21+00:00

I am a C/C++ programmer, but I was asked to update a program that

  • 0

I am a C/C++ programmer, but I was asked to update a program that was written in C# to communicate with a device. My knowledge of C# is very basic.

The previous version was totally written in C#, but now the API that in fact access the device was changed to C. I found out that I can import the C function APIs by using:

[DllImport("myapi.dll")]
public static extern int myfunct( 
                                 [MarshalAs(UnmanagedType.LPTStr)] string lpDeviceName,
                                 IntPtr hpDevice);

In C this function prototype is:

int myFunct( LPTStr lpDeviceName, HANDLE* hpDevice );

Where HANDLE is defined as :

typedef void *HANDLE;

However this function does not work as expected. In fact, in the C# code call what kind of type I should declare and pass to the C# method?

Thanks for the help and sorry for any stupid question.

  • 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-15T17:37:22+00:00Added an answer on May 15, 2026 at 5:37 pm

    you are passing IntPtr instead of ref IntPtr, the definition should look like this:

    [DllImport("myapi.dll")]
    public static extern int myfunct( 
        [MarshalAs(UnmanagedType.LPTStr)] string lpDeviceName,
        ref IntPtr hpDevice);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i know this question was asked before but i have this very weird beginner
I have already asked this question on SuperUser but it was suggested there that
I know that this question asked a lot (i think) but i could not
Our customer has asked that our application be able to communicate through HTTPS. The
I am a C# programmer but I have to work with some VB.Net code
I am a C# programmer but dabbling in VB.Net because everybody else in my
I'm not much of a programmer but I want to integrate http://storify.com/ into my
I am fairly experienced C programmer but IOS is new for me. I do
I'm not generally a GUI programmer but as luck has it, I'm stuck building
I'm an experienced Java programmer but am looking at some JavaScript/HTML5 stuff for the

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.