Connecting Tech Pros Worldwide Forums | Help | Site Map

callback function problem

Tomaz Rotovnik
Guest
 
Posts: n/a
#1: Nov 22 '05
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



Mattias Sjögren
Guest
 
Posts: n/a
#2: Nov 22 '05

re: callback function problem


Tomaz,
[color=blue]
>I think I override stack pointer. How can I trace down the problem?[/color]

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.
Tomaz Rotovnik
Guest
 
Posts: n/a
#3: Nov 22 '05

re: callback function problem


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" <mattias.dont.want.spam@mvps.org> wrote in message
news:uBj9PVV%23EHA.2700@TK2MSFTNGP14.phx.gbl...[color=blue]
> Tomaz,
>[color=green]
> >I think I override stack pointer. How can I trace down the problem?[/color]
>
> 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.[/color]


Diego
Guest
 
Posts: n/a
#4: Nov 22 '05

re: callback function problem


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 burlando@dmm888.com

"Tomaz Rotovnik" wrote:
[color=blue]
> 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
>
>
>[/color]
Closed Thread