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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:54:37+00:00 2026-06-12T11:54:37+00:00

I have an one question when I use C# DllImport C++ dll, I use

  • 0

I have an one question when I use C# DllImport C++ dll, I use the visual studio 2010 & checked the “Enable unmanaged code debugging”, when it’s running, always show the message “Buffer overrun detected! … A buffer overrun has been detected which has corrupted the program’s internal state. The program cannot safely continue execution and must now be terminated.”

This dll is Third-party vendors to provide, and they says it’s no error to run this dll, how can i fixed it?

My M++ dll function is,

int  avc_to_avi_convert(char* chPath_avc, char* chPath_avi, int pPrivate, PROGRESS_CALLBACK progress_callback);

void avc_to_avi_close(int* pFd_avi);

typedef void (*PROGRESS_CALLBACK)(int iPercent, int pPrivate);

And i am use it in my C# dllimport like this :

public delegate void PROGRESS_CALLBACK(int _iPercent, int _pPrivate);

[DllImportAttribute(@"..\xxx.dll", EntryPoint = "avc_to_avi_convert", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]

public static extern unsafe int avc_to_avi_convert([MarshalAs(UnmanagedType.LPStr)] StringBuilder _inputAVC, [MarshalAs(UnmanagedType.LPStr)] StringBuilder _ouputAVI, int pPrivate, PROGRESS_CALLBACK _pg);

[DllImportAttribute(@"..\xxx.dll", EntryPoint = "avc_to_avi_close", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode)]

public static extern unsafe void avc_to_avi_close(int pFd_avi);

private void button1_Click(object sender, EventArgs e)
{
    int i = 0;
    StringBuilder inputFile = new StringBuilder(Application.StartupPath + @"\avc\abc.avc");//(@"C:\avc\abc.avc");
    StringBuilder outputFile = new StringBuilder(Application.StartupPath + @"\avi\abc.avi");//(@"C:\avi\abc.avi");

    if (avc_to_avi_convert(
        inputFile,
        outputFile,
        1,
        progress_func) > 0) { 

    }
}

public void progress_func(int iProgress, int pPrivate)
{
     if (iProgress == 100)
     {
         //success
     }
     else if (iProgress == -1)
     {
         //convert error
     }
     else if (iProgress == -2)
     {
         //Not enough disk space
     }
     else
     {
         //update progress
     }
}

I changed my code to,

[DllImportAttribute(@"..\xxx.dll", EntryPoint = "avc_to_avi_convert", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]

public static extern unsafe int avc_to_avi_convert([MarshalAs(UnmanagedType.BStr)] String _inputAVC, [MarshalAs(UnmanagedType.BStr)] String _ouputAVI, int pPrivate, PROGRESS_CALLBACK _pg);

[DllImportAttribute(@"..\xxx.dll", EntryPoint = "avc_to_avi_close", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]

public static extern void avc_to_avi_close(ref int avi);

And ran it, and I still get the same error.

  • 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-12T11:54:39+00:00Added an answer on June 12, 2026 at 11:54 am

    1.) Are you sure about the calling convention? Try CallingConvention.StdCall. Read this:

    http://blogs.msdn.com/b/adam_nathan/archive/2003/05/21/56690.aspx

    2.) Try a different values for the CharSet attribute and use String instead of StringBuilder for the path arguments. This is a good reference:

    http://msdn.microsoft.com/en-us/library/s9ts558h.aspx

    3.) Also, the avc_to_avi_close method should look like this:

    [DllImportAttribute("xxx.dll", EntryPoint="avc_to_avi_close")]
    public static extern void avc_to_avi_close(ref int avi);
    

    4.) Other things you my want to try:

    • Use unusual combinations of CharSet and MarshalAs. For example you know from the link above that Unicode should be used with LPWStr and Ansi with LPStr but you can of course try other combinations.
    • Your extern methods need not to be marked unsafe.

    If you have exhausted all other options, why don’t you try to write a C++ program that is analogous to your C# code:

    • If it crashes you proved that the error is in the library.
    • If it doesn’t crash you know the error is in your use of PInovke, and you can go through all the 12+ combinations from my answer one by one.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have raise one question in my mind that Why we are frequently use
I have one question, I want to use redirected error output file or table
I have one question, When I use the aurio recording on my program, it
I have one more question about customizing emacs for use with an R session.
I have got one question, how to use javascript replace() in div tag? I
I just have one simple question. Everytime I use CGRectIntersectsRect(view1.frame, view2.frame) I get a
I've been following this tutorial, which is great btw, and have one question. http://www.larryullman.com/2010/01/07/custom-authentication-using-the-yii-framework/
Other questions dealing with use of match_parent pre 2.2 have answers stating one should
i have one question about jquery ajax().. I created a table grid and there
I have one question; In my ASP.NET MVC web application have to do certain

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.