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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:39:42+00:00 2026-06-16T14:39:42+00:00

I am working on a C# application which uses an unmanaged dll which as

  • 0

I am working on a C# application which uses an unmanaged dll which as a method that takes in a function pointer as one of it’s parameters. As I do not have access to the actual C++ source code for the unmanaged dll I can only rely on a snippet I have from a C++ sample which uses that the same dll. The problem I am having is that the delegate I have made to pass into the unmanaged method is not working.

Below is the DllImport of the method I am trying to use which takes the delegate I’ve created:

[DllImport("pos_tk.dll")]
static internal extern ErrorCode AddSIGHandle([MarshalAs(UnmanagedType.FunctionPtr)] SIG_Callback func);

Here is the delegate signature I currently have:

[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate void SIG_Callback ([MarshalAs(UnmanagedType.LPArray)] ref int[] buf, int rev, object sender);

And this is the function the C++ sample snippet uses in which I based my delegate off of:

void __stdcall point_handle (int *buf, int rev, LPVOID pParam)

Now, before you tell me to change the ref int[] buf parameter of my delegate to ref int buf the program will throw an InvalidVariant error once the callback is attempted. The code snippet uses int *buf as an array of size rev.

Using the code I have above, the application throws an AccessViolationException when the callback is attempted. My hunch is that I should be using a different type for the ref int[] buf parameter, but I’ve tried everything I can think of. I’ve also been searching Google, SO, and MSDN all day but with no luck.

Anyone have any ideas?

As a final note, is this any way similar to how you can use a StringBuilder as a parameter for a unmanaged method that takes a char* parameter to retrieve a variable length string?

  • 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-06-16T14:39:44+00:00Added an answer on June 16, 2026 at 2:39 pm

    Passing arrays back and forth is always a PITA…try this signature, it seems applicable:

    [UnmanagedFunctionPointer(CallingConvention.StdCall)]
    public delegate void point_handle(
        [MarshalAs(UnmanagedType.LPArray, SizeParamIndex=1)]
        int[] buf,
        int rev,
        IntPtr pParam);
    

    EDIT: just to elaborate, when you’ve got a “C style” array (that is a T*) as well as the length both specified in the arguments, SizeParamIndex is your salvation; basically it says “Hey, there’s an unknown-length array coming in, but the parameter at this index will tell you how many of them there are. Use both that and the type to help marshal”

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

Sidebar

Related Questions

I am working on a web application which uses the FileUpload control. I have
I am working under java application which uses XSLT transformation. I have a lot
I've been working on an application which uses a GSM modem for one of
We noticed that our application which uses netTcpBinding suddenly stopped working. After examining the
I am working on an application which uses bump technology.I do have four tab
I'm working on an application which uses SQLite Database on Android.I have a custom
So I have an application which uses C2DM messaging. It's working perfectly in the
I have a struts2 application which uses the struts2-rest-plugin v.2.2.3. Everything is working great
I'm working on a web based application which uses a JSON over HTTP based
I am currently working on a sample application which uses QNetworkAccessManager to send 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.