Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello I am making a PInvoke call from VB layer to the c++ DLL and getting the below erro?

A callback was made on a garbage collected delegate of type 'EPSS06!EPSS32.ErrorUtilities+delbpeErrCB::Invoke'. This may cause application crashes, corruption and data loss. When passing delegates to unmanaged code, they must be kept alive by the managed application until it is guaranteed that they will never be called.


Does anyone have any idea what the problem is?
Posted
Comments
Sergey Alexandrovich Kryukov 25-Apr-13 15:40pm    
Yes, it may. You need to show some code sample, both managed and unmanaged parts; please make is as simple as you can, focusing only this problem, nothing else.
—SA
[no name] 25-Apr-13 16:40pm    
Did you read the error message?
Philippe Mori 25-Apr-13 19:23pm    
As explained in the error message, if you call some unmanaged code that access memory from managed memory, you have to ensure that the pointer is properly pined so that is won't be garbage collected neither moved while being used by unmanaged code.

I don't know how you do that in VB (and if it can be done) but you have to read documentation and ensure that you understand what you are doing if you make callback from C++ code to managed VB code.

1 solution

We have asked for code as this may help explain where your going wrong. If you do not participate then how do you expect to get help?

It could be a scope problem.

Local:

VB
Public Class FooForm
  Private Sub Foo()
    Dim obj As Object = {something}
  End Sub ' obj now does not exist and gets collected
End Class


Class:
VB
Public Class FooForm
  Private obj As Object
  Private Sub Foo()
    obj = New Object
  End Sub 'obj still exist since the class holds the variable til it is collected
End Class
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900