473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with unmanaged DLL callbacks

I have a c# application, which calls a dll (which I made, so I can
modify the source code), passes there several parameters. The Dll
contains a thread pool. In the entry function which is called from c# a
new job is assigned to the thread pool. As soon as job is completed in
a separate thread, is calls back (from the thread) to the C#
application.

The problem is that sometimes (not at each time when the dll is called)
I'm getting a
Run-Time Check Failure #0 caused by different calling convention of a
pointer to the function an the function itself.

Here is the a hardly simpified source code of the DLL and of the C#
app:

*********[DLL src]************

typedef void (__stdcall *THREAD_CALLBACK)(char* s, int id);

//Entry function of the DLL
extern "C" __declspec(dllexport)
int _stdcall r(char* url_ptr, char* ip_ptr, int port, THREAD_CALLBACK
callback, int id)
{
/* Filling wp structure wp*/
.....................
/*and assiging a task to the thread pool*/
THREAD_POOL_TASK taskInfo = {id, worker, LPVOID(wp)};
m_Pool.AssignTask(&taskInfo);

return 0;
}

bool _cdecl worker(UINT taskId, LPVOID pData)
{
WORKER_PARAMS* wp = ((PWORKER_PARAMS)pData);
THREAD_CALLBACK callback = wp->callback;
......................................
/*Doing some job here and the calling back to the C# app:*/
callback(wbuf, id);
return true;
}

*********[C# src]************

[DllImport("winhttp_dll.dll", CallingConvention =
CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
public static extern int r(StringBuilder url_ptr, StringBuilder
ip_ptr, int port, Callback cb, int id);

[UnmanagedFunctionPointer(CallingConvention.StdCall )]
public delegate void DelegatePopulateGrid(string s, int i);

public delegate void Callback(int address, int id);
public static Callback ArpCallback;

/* In some function we call */

ArpCallback = new LiveMonitor.Callback(this.RecieveResponse);
r(url, ip, port, ArpCallback, row_index);

/*In Recieve Response we do some job and return*/
So the problem is that the error occurs SOMETIMES. And not very often
since the amount of calls in significant. Also I have to say that in
important places semaphores are placed.

Thank you for your concideration and sorry my crappy english.
Anton.

Jul 27 '06 #1
0 1402

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: vijaya | last post by:
I've to invoke a unmanaged dll fucntion in C# which uses a callback fucntion.The unmanaged dll fucntion returns a pointer to a structure to its callback fucntion.The user should collect those...
1
by: mynab | last post by:
Hello, I am facing an issue I cannot easily solve. I am writing a non-managed C++ application that I want to be extensible using plugins. The goal is to let people write plugins in any language...
2
by: tony lock | last post by:
I am trying to call an unmanaged dll from c#, the function is asyncronous and expects a callback function and a parameter which is labelled lpvoid but which expects the address of the calling object,...
11
by: Joe Martin | last post by:
Has anyone made use of PKWare's PKCDL.DLL for the Implode and Explode functions? I have been able to successfully define everything correctly and even get the invoked function (Explode) to run...
4
by: R. MacDonald | last post by:
Hello, all, I have a .NET application (VB) that passes the address of a delegate to unmanaged code in a DLL. The unmanaged code then uses the delegate as a call-back. This seems to work...
2
by: cada0310 | last post by:
Hi there, I'm new to C# (but not to C++), and I'm trying to create a web service that calls some of our older software, located in a DLL. I'm getting most the calls to work ok, but one of them...
6
by: per9000 | last post by:
An interesting/annoying problem. I created a small example to provoke an exception I keep getting. Basically I have a C-struct (Container) with a function-pointer in it. I perform repeated calls...
3
by: kelvin.koogan | last post by:
I have an unmanaged DLL which calls my managed C++ app using a callback (standard C++ function pointer). I can receive the callbacks OK using a static function with global scope, but I can't find a...
8
by: DavidT | last post by:
Hello, at first, exuse if the following question is simple to solve, but i normaly coding with C# and now have to use C++/CLI for one project. My Problem is that i have to use a native c++ sdk...
1
by: Jean-Paul Calderone | last post by:
On Tue, 10 Jun 2008 22:46:37 -0700 (PDT), George Sakkis <george.sakkis@gmail.comwrote: This isn't true. Access is synchronized automatically by virtue of the fact that there is no pre-emptive...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.