Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. CoInitialize has not been called

CoInitialize has not been called

Scheduled Pinned Locked Moved Visual Basic
helpcomjson
5 Posts 3 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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.

    S 1 Reply Last reply
    0
    • L Lost User

      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.

      S Offline
      S Offline
      Sam C
      wrote on last edited by
      #2

      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

      S 1 Reply Last reply
      0
      • S Sam C

        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

        S Offline
        S Offline
        Sam C
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • S Sam C

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          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. :((

          K 1 Reply Last reply
          0
          • L Lost User

            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. :((

            K Offline
            K Offline
            Klaus Probst
            wrote on last edited by
            #5

            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]

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups