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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:55:33+00:00 2026-05-29T07:55:33+00:00

I have the following function: bool __declspec(dllexport) COMS_HL7QueryAnswer(char *szZone,char* szMessage, char** o_szAnswer) And I’m

  • 0

I have the following function:

bool __declspec(dllexport) COMS_HL7QueryAnswer(char *szZone,char* szMessage, char** o_szAnswer)

And I’m PInvoking it from C# like this:

public static extern bool COMS_HL7QueryAnswer(string szZone,string szMessage, out StringBuilder szAnswer);

It’s working in Windows 2003 but I’m getting access violation exceptions in W2008 and looks like they happen in the boundary of the PInvoke. Any help will be great.

Thanks.

EDIT: Looks like the AccessViolationException happens in the PInvoke boundary because:

  1. I don’t have a callstack other than the C# function.
  2. When I go with the debugger I can F10 until the last C++ function and when I exit the } then I go to the C# exception handler.
  • 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-29T07:55:34+00:00Added an answer on May 29, 2026 at 7:55 am

    You’ll need to use

    [DllImport(CallingConvention = CallingConvention.Cdecl)]
    public static extern bool COMS_HL7QueryAnswer(string szZone,string szMessage, out IntPtr szAnswer);
    

    Because p/invoke has no idea how to correctly free *o_szAnswer, you’ need to keep the pointer and pass it to the correct deallocation function yourself, after retrieving the data.

    If you are allowed to change the C++ side, there are a number of things you can do to make this more p/invoke-friendly. Or you can use a C++/CLI layer.

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

Sidebar

Related Questions

I have the following function that is pulling data from a database. The ajax
Say I have the following function: bool foo (int a); // This method declaration
I have the following function (which worked in Visual Studio): bool Plane::contains(Vector& point){ return
I have the following vector passed to a function void WuManber::Initialize( const vector<const char
I have the following vexing problem. I have implemented the following function: function bool
Suppose I have the following function (pseudocode): bool checkObjects(a, b) { if ((a.isValid() &&
If I have the following function: -(BOOL) checkIfValid{ if(someThing){ return YES; } return NO;
I have the following function in c#: bool Handle<TCommandHandler, TModel>(TModel model) where TCommandHandler :
I have atleast 16 functions of the following form. bool Node::some_walker( Arg* arg1 )
I have the following function: CREATE FUNCTION fGetTransactionStatusLog ( @TransactionID int ) RETURNS varchar(8000)

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.