Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / January 2005

Tip: Looking for answers? Try searching our database.

buffer overrun

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alin - 08 Nov 2004 22:31 GMT
Hello,

I'm trying to get a callback from a custom dll into a C# application. I get
the correct callback, with the right parameters but when it gets out of the
scope of the callback method I get an exception (with Microsoft Visual C++
Runtime Library window title ) like: "Buffer overrun detected !! ... ". Any
idea where this comes from and why ? is it something in the dll I'm calling ?
Willy Denoyette [MVP] - 08 Nov 2004 23:25 GMT
Wrong calling convention? .NET V1.X  expect stdcall callbacks.

Willy.

> Hello,
>
[quoted text clipped - 7 lines]
> idea where this comes from and why ? is it something in the dll I'm
> calling ?
Alin - 09 Nov 2004 13:50 GMT
Willy,
Here's the situation: I have the dll, the lib and the C++ .h file. The
declaration of the method looks like:
ERROR Log(void (*CallBack)(LOG_LEVEL LogLevel, const char *src, const char
*dest));

In the C# code:
[DllImport("mydll.dll",CharSet=CharSet.Auto, SetLastError=true,
CallingConvention=CallingConvention.StdCall)]
private static extern void Log([MarshalAs(UnmanagedType.FunctionPtr)]
CallBack callback);
Where the delegate is declared as:
private delegate int CallBack(
    [MarshalAs(UnmanagedType.U4)] uint logLevel,
               [MarshalAs(UnmanagedType.LPStr)] string src,
    [MarshalAs(UnmanagedType.LPStr)] string dest);

The callback method looks like:
private static int Log(uint logLevel, string src, string dest)
        {
            Console.WriteLine(src + " :: " + dest);           
            int hh = Marshal.GetLastWin32Error();
            //error returned here:: 126 The specified module could not be found.
ERROR_MOD_NOT_FOUND
            return 0;   
        }

So, I get the callback from the dll, with the right data passed as
parameters. The only problem is when the execution exists the scope of the
Log method it shows that error with buffer overrun. GetLastWinError returns
an ERROR_MOD_NOT_FOUND (126) error.
I'll check if the dll uses stdcall. Any other ideas ?

> Wrong calling convention? .NET V1.X  expect stdcall callbacks.
>
[quoted text clipped - 11 lines]
> > idea where this comes from and why ? is it something in the dll I'm
> > calling ?
Blair Hamilton - 05 Jan 2005 22:39 GMT
I haven't been able to find the documentation, is there a way to change the
delegate calling convention in .NET 2.0? I don't like having to use the IL
hack.

> Wrong calling convention? .NET V1.X  expect stdcall callbacks.
>
[quoted text clipped - 11 lines]
> > idea where this comes from and why ? is it something in the dll I'm
> > calling ?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.