从c ++线程调用VB6函数指针 [英] Calling to a VB6 function pointer from a c++ thread

查看:132
本文介绍了从c ++线程调用VB6函数指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从线程调用指针。

这是我的代码:



myDll.dll c ++:

I'm trying to call from a thread to a pointer.
Here is my code:

myDll.dll c++ :

long cbAddrAsync;
void _asyncer(void* data)
{
        typedef void (__stdcall *FUNCPTR)();
    FUNCPTR vbFunc;
    vbFunc = (FUNCPTR)cbAddrAsync;
    vbFunc();
}
extern "C" __declspec(dllexport) void async(long addr)
{
    cbAddrAsync = addr;
    HANDLE hHandle = (HANDLE)_beginthread(_asyncer,0,NULL);
}





用vb6跟这个extern打电话:

在Module1中:



calling to this extern with vb6:
In Module1:

Declare Sub async Lib "myDll.dll" (ByVal addr As Long)
Sub onAsync()
MsgBox "ASYNC"
End Sub



Form1:




In Form1:

Private Sub Command_Click()
Call async(AddressOf Module1.onAsync)
End Sub

<当我点击命令按钮时,


,问题发生在DLL中:

Project1.exe中0x734f9232处的未处理异常:0xC0000005:访问冲突读取位置0x00000076。

in vbFunc();



如何解决?

谢谢。



when i click at command button , The problem occurs in dll:
Unhandled exception at 0x734f9232 in Project1.exe: 0xC0000005: Access violation reading location 0x00000076.
in vbFunc();

How can I fix it?
Thanks.

推荐答案

你的问题是你启动了一个访问现有UI-Thread的新线程。仅使用另一个线程更改数据,并以另一种方式向GUI发送信号。



我不太适合在vb.net同步,但有些线程同步应该解决这个问题。



请在评论中提供您的解决方案。
your problem is that you start a new thread which accesses the existing UI-Thread. Only change data with another thread and signal it another way to the GUI.

I am not so fit in sync in vb.net but some Thread Synchronization should resolve that.

Please provide your solution in a comment.


这篇关于从c ++线程调用VB6函数指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆