CoInitialize has not been called
-
I am using visual basic to develop an application using a VB ActiveX dll I have created a multithreading tech. using window API function CreateThread(...) like this :- ------------------------This laid in XClass in the ActiveX dll------------- lRet = CreateThread(0, _ 0, _ AddressOf TheThread, _ 0, _ 0, _ lThreadID) ----------------------------This thread Function is laid in some module------- Public Function TheThread(ByRef p As PARAMETER) As Long On Error GoTo TheThread_Error XClass.SpecialFunction Exit Function TheThread_Error: MsgBox ("TheThread had an error : " + Err.Description) End Function But there is a run time error message comes up say "CoInitialize has not been called" Can some body help me. Thanks.
-
I am using visual basic to develop an application using a VB ActiveX dll I have created a multithreading tech. using window API function CreateThread(...) like this :- ------------------------This laid in XClass in the ActiveX dll------------- lRet = CreateThread(0, _ 0, _ AddressOf TheThread, _ 0, _ 0, _ lThreadID) ----------------------------This thread Function is laid in some module------- Public Function TheThread(ByRef p As PARAMETER) As Long On Error GoTo TheThread_Error XClass.SpecialFunction Exit Function TheThread_Error: MsgBox ("TheThread had an error : " + Err.Description) End Function But there is a run time error message comes up say "CoInitialize has not been called" Can some body help me. Thanks.
What version of VB are you using? I have heard that using threads within VB6 is highly unstable and causes a lot of problems. Here's a snippet from Dan Appleman, and the Desaware site:
Sigh... It seems that many readers missed my original point. The ideas was not to encourage VB programmers to use CreateThread with Visual Basic. It was to explain clearly and accurately why you shouldn't use CreateThread with Visual Basic.
So, when Visual Basic 6 turned out to be considerably less thread-safe than VB5, breaking the sample programs referenced by this article, what could I do? I suppose I could go back and revise the samples and try to make them work with VB6. But then the same problem might arise with later versions of Visual Basic as well.
Visual Basic offers good support of multithreading including multithreaded clients in ActiveX servers (this is described quite thoroughly in the latest edition of my Developing COM/ActiveX components book). I strongly encourage you to stay within the rules defined by the Visual Basic documentation and not use the CreateThread API with Visual Basic.
For those who insist on pursuing CreateThread further, to start with you should eliminate all Declare statements and use a type library instead. I don't promise that this will fix the problem, but my initial testing indicates that it is a necessary first step.
If you want the entire article goto http://www.desaware.com/articles/threadingL3.htm, his articles are knowledgable, and he is also the guy who write Win32API for Visual Basic programemrs. Have a copy of that on my desk, err...wait, no, yeah, I'm a pure VC++ programmer =) Sam C ---- Systems Manager Hospitality Marketing Associates
-
What version of VB are you using? I have heard that using threads within VB6 is highly unstable and causes a lot of problems. Here's a snippet from Dan Appleman, and the Desaware site:
Sigh... It seems that many readers missed my original point. The ideas was not to encourage VB programmers to use CreateThread with Visual Basic. It was to explain clearly and accurately why you shouldn't use CreateThread with Visual Basic.
So, when Visual Basic 6 turned out to be considerably less thread-safe than VB5, breaking the sample programs referenced by this article, what could I do? I suppose I could go back and revise the samples and try to make them work with VB6. But then the same problem might arise with later versions of Visual Basic as well.
Visual Basic offers good support of multithreading including multithreaded clients in ActiveX servers (this is described quite thoroughly in the latest edition of my Developing COM/ActiveX components book). I strongly encourage you to stay within the rules defined by the Visual Basic documentation and not use the CreateThread API with Visual Basic.
For those who insist on pursuing CreateThread further, to start with you should eliminate all Declare statements and use a type library instead. I don't promise that this will fix the problem, but my initial testing indicates that it is a necessary first step.
If you want the entire article goto http://www.desaware.com/articles/threadingL3.htm, his articles are knowledgable, and he is also the guy who write Win32API for Visual Basic programemrs. Have a copy of that on my desk, err...wait, no, yeah, I'm a pure VC++ programmer =) Sam C ---- Systems Manager Hospitality Marketing Associates
Ok screwed up with the last article, I can't even see the modify button weird. But here's some advice don't use the >PRE< tags for website articlesSorry, Chris. Well, here's the article again about threads in VB6 from our guy Dan: Sigh... It seems that many readers missed my original point. The ideas was not to encourage VB programmers to use CreateThread with Visual Basic. It was to explain clearly and accurately why you shouldn't use CreateThread with Visual Basic. So, when Visual Basic 6 turned out to be considerably less thread-safe than VB5, breaking the sample programs referenced by this article, what could I do? I suppose I could go back and revise the samples and try to make them work with VB6. But then the same problem might arise with later versions of Visual Basic as well. Visual Basic offers good support of multithreading including multithreaded clients in ActiveX servers (this is described quite thoroughly in the latest edition of my Developing COM/ActiveX components book). I strongly encourage you to stay within the rules defined by the Visual Basic documentation and not use the CreateThread API with Visual Basic. For those who insist on pursuing CreateThread further, to start with you should eliminate all Declare statements and use a type library instead. I don't promise that this will fix the problem, but my initial testing indicates that it is a necessary first step. ------------------------------------------- And here's his website pretty much a VB guru: http://www.desaware.com/articles/threadingL3.htm. Good luck with threading and if you come across this Chris you may want to delete the above post because I can't get to the modify or delete link =) Sam C ---- Systems Manager Hospitality Marketing Associates
-
Ok screwed up with the last article, I can't even see the modify button weird. But here's some advice don't use the >PRE< tags for website articlesSorry, Chris. Well, here's the article again about threads in VB6 from our guy Dan: Sigh... It seems that many readers missed my original point. The ideas was not to encourage VB programmers to use CreateThread with Visual Basic. It was to explain clearly and accurately why you shouldn't use CreateThread with Visual Basic. So, when Visual Basic 6 turned out to be considerably less thread-safe than VB5, breaking the sample programs referenced by this article, what could I do? I suppose I could go back and revise the samples and try to make them work with VB6. But then the same problem might arise with later versions of Visual Basic as well. Visual Basic offers good support of multithreading including multithreaded clients in ActiveX servers (this is described quite thoroughly in the latest edition of my Developing COM/ActiveX components book). I strongly encourage you to stay within the rules defined by the Visual Basic documentation and not use the CreateThread API with Visual Basic. For those who insist on pursuing CreateThread further, to start with you should eliminate all Declare statements and use a type library instead. I don't promise that this will fix the problem, but my initial testing indicates that it is a necessary first step. ------------------------------------------- And here's his website pretty much a VB guru: http://www.desaware.com/articles/threadingL3.htm. Good luck with threading and if you come across this Chris you may want to delete the above post because I can't get to the modify or delete link =) Sam C ---- Systems Manager Hospitality Marketing Associates
-
I used API createThread before in VB6 without any problem but I think my problem come from using an another many AvtiveX objects under the thread function and these objects need to initialize,but how these objects initialize in VB. best regards. :((
I used API createThread before in VB6 without any problem but I think my problem come from using an another many AvtiveX objects under the thread function and these objects need to initialize,but how these objects initialize in VB. best regards. It doesn't matter -- if it worked before it's just because you were lucky. If you want to learn how to do threads correctly in VB go out and buy Matt Curland's new book ___________ Klaus [www.vbbox.com]