Hello all,
I have a VERY simple windows application that decrypts data files we receive
from a partner. The decryption is handled by a COM component our partner
provided us with (thus we have no control over its functionality). That,
however, works fine. To make it a little easier for our end users, I wanted
to include a feature that places the path and name of the decrypted file on
the clipboard. I was going to do this by using
Clipboard.SetDa taObject(sNameP ath). However when I run the application, I
receive an error stating:
"The current thread must set to Single Thread Apartment (STA) mode before
OLE calls can be made. Ensure that your Main function has STAThreadAttrib ute
marked on it."
The error occurs on the Clipboard.SetDa taObject line. I don't have a 'Main'
function (I tried putting a Main sub in with a Application.Run (Form1) and
mark it with the <STAThreadAttri bute> but with no change).
I built another windows app just to test the Clipboard.SetDa taObject and it
worked just fine...
I would be very grateful for some insight. I don't absolutely need this
feature, it just bugs me that it's not working and I don't know why.
Thanks,
Roy Gunnarsson 2 5259
Roy,
What kind of application is this? (Windows Forms, Windows Service, Console)
Are you attempting to use any async processing? (Begin*, ThreadPool)
VB.NET by default will make your main form STA, you should not need to add
it.
Is your program a single form, can you post a simple example that has the
problem, preferable on a website, however if its a small zip file you can
attach it here.
Hope this helps
Jay
"Roy Gunnarsson" <rg************ *******@excelsi or.edu> wrote in message
news:OG******** ******@TK2MSFTN GP09.phx.gbl... Hello all,
I have a VERY simple windows application that decrypts data files we
receive from a partner. The decryption is handled by a COM component our partner provided us with (thus we have no control over its functionality). That, however, works fine. To make it a little easier for our end users, I
wanted to include a feature that places the path and name of the decrypted file
on the clipboard. I was going to do this by using Clipboard.SetDa taObject(sNameP ath). However when I run the application, I receive an error stating:
"The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made. Ensure that your Main function has
STAThreadAttrib ute marked on it."
The error occurs on the Clipboard.SetDa taObject line. I don't have a
'Main' function (I tried putting a Main sub in with a Application.Run (Form1) and mark it with the <STAThreadAttri bute> but with no change).
I built another windows app just to test the Clipboard.SetDa taObject and
it worked just fine...
I would be very grateful for some insight. I don't absolutely need this feature, it just bugs me that it's not working and I don't know why.
Thanks,
Roy Gunnarsson
You are calling Application.Run from main sub. Take a good look at the code.
That's where you have to set STA model.
Also check project properties, if I remember correctly, there is something
there related to STA/MTA too.
HTH
Alex
"Roy Gunnarsson" <rg************ *******@excelsi or.edu> wrote in message
news:OG******** ******@TK2MSFTN GP09.phx.gbl... Hello all,
I have a VERY simple windows application that decrypts data files we
receive from a partner. The decryption is handled by a COM component our partner provided us with (thus we have no control over its functionality). That, however, works fine. To make it a little easier for our end users, I
wanted to include a feature that places the path and name of the decrypted file
on the clipboard. I was going to do this by using Clipboard.SetDa taObject(sNameP ath). However when I run the application, I receive an error stating:
"The current thread must set to Single Thread Apartment (STA) mode before OLE calls can be made. Ensure that your Main function has
STAThreadAttrib ute marked on it."
The error occurs on the Clipboard.SetDa taObject line. I don't have a
'Main' function (I tried putting a Main sub in with a Application.Run (Form1) and mark it with the <STAThreadAttri bute> but with no change).
I built another windows app just to test the Clipboard.SetDa taObject and
it worked just fine...
I would be very grateful for some insight. I don't absolutely need this feature, it just bugs me that it's not working and I don't know why.
Thanks,
Roy Gunnarsson
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Wayne Wengert |
last post by:
I have an aspx page on which I am trying to copy the contents of a textbox
to the client clipboard when the users clicks a button. The button code is
as follows:
=====================================
Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCopyToClipboard.Click
Clipboard.SetDataObject(txtHidden.Text)
End Sub
|
by: Tim Frawley |
last post by:
I have converted a VB6 application to VB.NET. The old application
made extensive use of the Clipboard for copying an Image Name so that
it could be pasted into the image capture app when the user scans the
image. My applications run as compiled assemblies from our Intranet
server and I have setup a Main sub routine in the application with the
following line:
<STAThread()> Public Sub Main()
Note: There is no timer in this application.
|
by: SAL |
last post by:
I have the following VB.net Class/Function that I call from an ASP.net page:
Public Class MyTestClass
Public Function embedHyperlink(ByVal fileID As Integer, ByVal fileName
As String) As String
'Create a New Instance of the HyperLink Control
Dim createHyperLink As New System.Web.UI.WebControls.HyperLink
'Create an Instance of the ClipBoard Object
|
by: renfes |
last post by:
Hey everyone. I have a program that watches a .txt log file from a chat
client or a game and based on each line, triggers events. One thing I
am trying to do is send the contents of a text file to the clipboard,
then paste it to the program... Here is the code I am using...
namespace Project1
{
public partial class Form1 : Form
{
|
by: Sefner |
last post by:
Hey everyone. I have a program that watches a .txt log file from a chat
client or a game and based on each line, triggers events. One thing I
am trying to do is send the contents of a text file to the clipboard,
then paste it to the program... Here is the code I am using...
namespace Project1
{
public partial class Form1 : Form
{
| |
by: Sin Jeong-hun |
last post by:
class Engine
{
Thread Worker;
public event ... EngineMessage;
public void Start()
{
Worker=new Thread(new ThreadStart(Run));
Worker.Start();
}
private Run()
|
by: Curious |
last post by:
I got the error when I execute the following line of code:
Clipboard.SetDataObject(mGrid.Clip);
The error is:
"Current thread must be set to single thread apartment (STA) mode
before OLE calls can be made. Ensure that your Main function has
STAThreadAttribute marked on it."
|
by: asmapanjabi |
last post by:
am using C#.net 1.1 while using clipboard m geeting this exception
System.Threading.ThreadStateException: Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it.
at System.Windows.Forms.Clipboard.GetDataObject()
|
by: Max2006 |
last post by:
Hi,
No matter what I have in clipboard Clipboard.GetDataObject(); returns null.
I suspect it might be a problem with Vista or VS2008 IDE debug mode problem?
Is there any way to track why the following statement is always null?
IDataObject iData = Clipboard.GetDataObject();
Thank you,
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |