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 / July 2004

Tip: Looking for answers? Try searching our database.

Delegate Problem.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GB - 30 Jun 2004 12:32 GMT
Dear all,

I am using a Delegate to callback from a C dll which
takes in input a function pointer. The Delegate is
called back and the struct is filled properly, but
just after the delegate function finishes, the
application crashes. "Memory cannot be written" The
application referenced memory at "fff000" ...

The Post routine (delegate) takes in an argument x25doneinfo
which belongs to the unmanaged code (I am NOT passing it to the
delegate call), it is just returned whenever the post function is
called.
can this be a problem (as I am not allocating memory to this
structure).
This structure is not defined in the unmanaged code as well (The
network driver returns this structure)

I want to use this structure as it contains the network packet data.

I am working on this problem for quite some days now so
will be grateful if someone can help me with this.

The C# code is like this :

class  Networking
{
public unsafe delegate void PostDelegate(ref
DataStructures.x25doneinfo doneInfo);   

public PostDelegate post;

[DllImport("Networking.dll")]
public static extern unsafe int recvPacket(int
iCid,IntPtr Buffer, int PacketSize, ref int iInfo,
[MarshalAs(UnmanagedType.FunctionPtr)] Delegate
PostDelegate);

void Recvpacket() {

     while (1)
      {
      post = new PostDelegate(postFunction);

     //Calling the C dll function with the Delegate
      if( recvPacket(FormMain.callportNumber,cpRecvBuffer,
                     PACKET_SIZE, ref iInfo, post) < 0 )
           {
              MessageBox.Show("recv error");
                       
            }

     }

}

public unsafe void postFunction(ref
DataStructures.x25doneinfo DoneInfo)
{

string error = "";
char[] mapBuff = new char[1050];
this.doneInfo = DoneInfo;

try
{
// process the packet
}

}---->>> after this point the application CRASHES

}
with the above error. Please see if you can help.

Thanks,
Gaurav
Robert Jordan - 03 Jul 2004 21:21 GMT
> I am using a Delegate to callback from a C dll which
> takes in input a function pointer. The Delegate is
> called back and the struct is filled properly, but
> just after the delegate function finishes, the
> application crashes. "Memory cannot be written" The
> application referenced memory at "fff000" ...

this might be a calling convention issue.
the C-DLL is probably expecting a "cdecl" callback.
if you own the sources of that DLL then change the
calling convention to WINAPI.
if not, take a look at

http://groups.google.com/groups?selm=ew6mLkV6BHA.1932%40tkmsftngp03

rob

Rate this thread:







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.