473,473 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
Nov 20 '05 #1
2 2372
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" <kw*****@yahoo.com> wrote in message
news:eZ**************@TK2MSFTNGP10.phx.gbl...
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" <id*************************@reallyidont.com> wrote in
message news:cc******************@news.demon.co.uk...
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


Nov 20 '05 #2
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.
Nov 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: James | last post by:
Running on Xp with WSAD5.0.1 (acts the same in 5.1) an action class is simply not being called when it is configured identically with others called in the same manner. It never gets into the...
7
by: Douglas Peterson | last post by:
Take a look at this code, it looks funny as its written to be as short as possible: -- code -- struct Base { ~Base() { *((char*)0) = 0; } }; struct Derived : public Base
1
by: kosta | last post by:
hello! I have this code: public static DataSet DSet(String sql) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = ConfigurationSettings.AppSettings; OleDbCommand cmd =...
4
by: jodyblau | last post by:
I have search the Groups for help on this, and found some examples of people trying to do something similar to what I am trying to do, but wasn't able to get any of the examples to work. What I...
7
by: ankitjain.bvcoe | last post by:
I have an existing C++ library . Now i am another application using this C++ lib. The problem here is i want to call C++ fn. from C file .If i use an extern "C"declaration for that fn. then the...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
12
by: semedao | last post by:
Hi all, someone know if I can use the IAsyncResult.IsCompleted Property of IAsyncResult that return from Socket.Beginxxx methods to determine if the Endxxx method already called perior or not ? I...
2
by: deciacco | last post by:
I have a NotifyIcon application. (c# 2) I want to be able to catch a kill/shutdown attempt so that I can call Dispose() to remove the icon. I tried to create an event handler for ApplicationExit...
8
Motoma
by: Motoma | last post by:
Good evening everyone. I am starting to re-explore C++, and I wanted to build a singleton class. Unfortunately, when I set things up as I do in PHP, it doesn't work out for me. I hope that the...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.