PC Review


Reply
Thread Tools Rate Thread

CoInitialise has not been called? Attempt to use OleSetClipboard.....

 
 
Robin Tucker
Guest
Posts: n/a
 
      12th Jul 2004
I need to use OleSetClipboard in my VB.NET application. Unfortunately, when
I do the result returned is -2147221008 (CoInitialise has not been called).
As I am using OleSetClipboard from a thread I've created, I was under the
impression that .NET automatically called CoInitialise the first time I used
a COM object in that thread. Is this the case? What other reason can there
be for this problem?

Thanks for any help you can give (here is the code I use to import
OleSetClipboard - note COM.IDataObject is my VB wrapper around
IDataObject)....


Public Declare Auto Function OleSetClipboard Lib "OLE32.DLL" _
(<MarshalAs(UnmanagedType.Interface)> ByVal theDataObject As
COM.IDataObject) As Integer


 
Reply With Quote
 
 
 
 
Ben Rush
Guest
Posts: n/a
 
      12th Jul 2004
Robin,

What happens when you do call CoInitialize()? It is my understanding that it
does not in personally-created threads. You may still have to introduce that
thread to a particular apartment first.

"Robin Tucker" <(E-Mail Removed)> wrote in
message news:ccu7ap$h9$1$(E-Mail Removed)...
> I need to use OleSetClipboard in my VB.NET application. Unfortunately,

when
> I do the result returned is -2147221008 (CoInitialise has not been

called).
> As I am using OleSetClipboard from a thread I've created, I was under the
> impression that .NET automatically called CoInitialise the first time I

used
> a COM object in that thread. Is this the case? What other reason can

there
> be for this problem?
>
> Thanks for any help you can give (here is the code I use to import
> OleSetClipboard - note COM.IDataObject is my VB wrapper around
> IDataObject)....
>
>
> Public Declare Auto Function OleSetClipboard Lib "OLE32.DLL" _
> (<MarshalAs(UnmanagedType.Interface)> ByVal theDataObject As
> COM.IDataObject) As Integer
>
>



 
Reply With Quote
 
Robin Tucker
Guest
Posts: n/a
 
      12th Jul 2004
I just tried it with:

m_ComInitialized = DLLImports.CoInitializeEx(0,
DLLImports.COINIT.COINIT_APARTMENTTHREADED)

Which returns zero (which I believe is S_OK).

BUT: this still results in "CoInitialize has not been called." HRESULT from
the OleSetClipboard. Note: my application is bracketed with <STAThread()> _
and my thread is created like this (ie. I do not specify an apartment model,
as I'm not to sure what it needs to be).

m_Thread = New Thread(New ThreadStart(AddressOf _Start))
If m_Thread Is Nothing Then
Exit Sub
End If



"Ben Rush" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Robin,
>
> What happens when you do call CoInitialize()? It is my understanding that

it
> does not in personally-created threads. You may still have to introduce

that
> thread to a particular apartment first.
>
> "Robin Tucker" <(E-Mail Removed)> wrote in
> message news:ccu7ap$h9$1$(E-Mail Removed)...
> > I need to use OleSetClipboard in my VB.NET application. Unfortunately,

> when
> > I do the result returned is -2147221008 (CoInitialise has not been

> called).
> > As I am using OleSetClipboard from a thread I've created, I was under

the
> > impression that .NET automatically called CoInitialise the first time I

> used
> > a COM object in that thread. Is this the case? What other reason can

> there
> > be for this problem?
> >
> > Thanks for any help you can give (here is the code I use to import
> > OleSetClipboard - note COM.IDataObject is my VB wrapper around
> > IDataObject)....
> >
> >
> > Public Declare Auto Function OleSetClipboard Lib "OLE32.DLL" _
> > (<MarshalAs(UnmanagedType.Interface)> ByVal theDataObject As
> > COM.IDataObject) As Integer
> >
> >

>
>



 
Reply With Quote
 
Mattias Sjögren
Guest
Posts: n/a
 
      12th Jul 2004
Robin,

>As I am using OleSetClipboard from a thread I've created, I was under the
>impression that .NET automatically called CoInitialise the first time I used
>a COM object in that thread. Is this the case?


By default it makes it an MTA thread. Make sure you set the thread's
ApartmentState property to STA before starting the thread.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
 
Reply With Quote
 
New Member
Join Date: Aug 2006
Posts: 1
 
      9th Aug 2006
Use OleInitialize instead of CoInitialize.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple sproc executes 240 times slower when called from asp.net thanwhen called from QA Radu Microsoft ASP .NET 6 27th Mar 2009 03:00 AM
Are sub-routines parameters called by reference or called by value? Thomas Lebrecht Microsoft VB .NET 2 25th Mar 2009 10:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.