473,385 Members | 1,185 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.

callback function problem

Hi

I created very simple dll (vc++) which has three functions (start, stop and
initialization). it starts capturing sound from soundblaster and when the
buffer is filled with the data, dll calls VB calback function (passed with
initialization) and passes the buffer size (integer type). First I have
some problems with __stdcall declaration in VC dll, but I think I solved
that
problem. Callback function runs in separated thread under main dll thread.

Declaration of initialization of callback function looks like this:

__declspec(dllexport) int __stdcall RecToR_Init_Cap(void (__stdcall
*tmp)(int_4 size));
IN VB:
Public Delegate Sub Callback(ByVal size As Int32)

Public Declare Function RecToR_Init_Cap Lib "RecToR_Cap_TR.dll" (ByVal
CalBckFunc As Callback) As Int32

"Private Sub Button1_Click" event in VB:

Dim cb As Callback
cb = AddressOf CallBackFunc
Success = RecToR_Init_Cap(cb)
Public Sub CallBackFunc(ByVal size As Int32)
TextBox1.Text = size & vbCrLf
End Sub
When I run the application, the callback function is called 50 times and
then the application crashes (it should work until stop is called):

"An unhandled exception of type
'System.Runtime.InteropServices.SEHException' occurred in Unknown Module.
Additional information: External component has thrown an exception.
An exception 'System.NullReferenceException' has occured in..."

I think I override stack pointer. How can I trace down the problem?

From Microsoft articles I get information that I cannot call callbacks from
spawned threads within my DLL.

Is it possible to overcome this problem?

Thanks for any idea
Tomaz Rotovnik
Jul 21 '05 #1
3 3377
Tomaz,
I think I override stack pointer. How can I trace down the problem?


I think its a GC problem.

http://www.dotnetinterop.com/faq/?q=DelegateGC

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2
Thank you for your answer. It was the right direction.

I just put the declaration of callback variable outside the
click button event.

Tomaz

"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uB****************@TK2MSFTNGP14.phx.gbl...
Tomaz,
I think I override stack pointer. How can I trace down the problem?


I think its a GC problem.

http://www.dotnetinterop.com/faq/?q=DelegateGC

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.

Jul 21 '05 #3
Hello Tomaz My name is Diego and I 'm from Italy. sorry not to have hints for
your problem but as your target applicaion is similiar to mine I woul like to
ask your help.
I 'm developing an application of voice over ip to send and receive sound.
I need to know how to create datagrams of voice through a buffer listening
from my audio device. It would be suitable for example capturing 2048 bytes
of wav format at a time and then send it trough a socket client using
callback as you know.
can you tell me how to capture voice from audio device in packets to buffer
away over IP?. Regards and best in busineess.
Diego. at bu******@dmm888.com

"Tomaz Rotovnik" wrote:
Hi

I created very simple dll (vc++) which has three functions (start, stop and
initialization). it starts capturing sound from soundblaster and when the
buffer is filled with the data, dll calls VB calback function (passed with
initialization) and passes the buffer size (integer type). First I have
some problems with __stdcall declaration in VC dll, but I think I solved
that
problem. Callback function runs in separated thread under main dll thread.

Declaration of initialization of callback function looks like this:

__declspec(dllexport) int __stdcall RecToR_Init_Cap(void (__stdcall
*tmp)(int_4 size));
IN VB:
Public Delegate Sub Callback(ByVal size As Int32)

Public Declare Function RecToR_Init_Cap Lib "RecToR_Cap_TR.dll" (ByVal
CalBckFunc As Callback) As Int32

"Private Sub Button1_Click" event in VB:

Dim cb As Callback
cb = AddressOf CallBackFunc
Success = RecToR_Init_Cap(cb)
Public Sub CallBackFunc(ByVal size As Int32)
TextBox1.Text = size & vbCrLf
End Sub
When I run the application, the callback function is called 50 times and
then the application crashes (it should work until stop is called):

"An unhandled exception of type
'System.Runtime.InteropServices.SEHException' occurred in Unknown Module.
Additional information: External component has thrown an exception.
An exception 'System.NullReferenceException' has occured in..."

I think I override stack pointer. How can I trace down the problem?

From Microsoft articles I get information that I cannot call callbacks from
spawned threads within my DLL.

Is it possible to overcome this problem?

Thanks for any idea
Tomaz Rotovnik

Jul 21 '05 #4

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

Similar topics

6
by: Marian Aldenhövel | last post by:
Hi, I am using the FMOD audio-library with the pyFMOD python bindings. pyFMOD uses ctypes. It is possible to register callback functions with FMOD that are called at certain points in the...
1
by: pvdm | last post by:
Hi, I am writing an app which encapsulates a multimedia timer. I implemented a TimerProc as static member function and a static member variable pThis as pseudo this variable to access in the...
1
by: Mohamed Fysal | last post by:
I have written a Regular DLL with many Export Functions and one CALLBACK fun ction . The callback function declared in the .cpp file of the Regular DLL is as fol lows: typedef BOOL...
3
by: Tomaz Rotovnik | last post by:
Hi I created very simple dll (vc++) which has three functions (start, stop and initialization). it starts capturing sound from soundblaster and when the buffer is filled with the data, dll calls...
3
by: ryan.mitchley | last post by:
Hi all I have a class (cPort) that is designed to receive objects and, depending on the type, call a handler (callback) in any descendant of a cProcessBlock class. Callback functions take a...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
5
by: Jef Driesen | last post by:
I have a C DLL that I want to use from a C# project. The C header file contains these declarations: typedef void (*callback_t) (const unsigned char *data, unsigned int size, void *userdata);...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?

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.