I have a vb windows application with 2 forms, where form2 is called from form1 using
form2.showdialog()
I added a web browser control to form2, and I'm getting the following error at the point where form2 is called:
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.
I tried:
1) adding STAThread() to the form_load()
2) I added a module to my application, and created a sub main(), with the STAThread attribute applied to it
3) I marked the sub startup() with STAThread()
And none of this helped.
Any tips on how to get around this issue?
Thanks,
rcpg
If you use the form project template and did not change anything in project settings you don't have control over the main function - the compiler will generate one that has STAThread for you.
Are you creating some objects (such as Timer) in the form whose type has a SynchronizingObject property and you forgot to assign a synchronizing object to it?
Related
I want to create a dialog utility unity that could be called in an asynchronous way from different threads and show my dialog message on the active form, and I was sure that TDialogServiceAsync was the perfect way to do it but I can't call the MessageDialog method from outside the Main UI Thread.
Is it possible to achieve what I want without having to actually create a method in my main form that shows the dialog?
I'm developing for Windows right now but a method that could work on multiple plataforms would be appreciated.
Thanks in advance.
no, everything that touch the ui must be done in the main ui thread (quite logic). the only think you can do in your background thread
TThread.queue(nil,
procedure
begin
showdialog...
end);
I am using PeriodicTask and ofcourse it runs for every 30 mins.Can we call the code of MainPage.xaml.cs file from ScheduledAgent.cs when OnInvoke method is fired ? I want to resued the code written in one of the method of MainPage.xaml.cs.
If that is not possible can i connect to the internet everytime the OnInvoke() method is fired and fetch the data and display them as tiles/toast ? Any suggestions would be really appreciated.
You can't use the code from MainPage in your background agent, because your main project must reference the background agent's project. So adding an additional reference from the background agent to the main project would create a cyclic dependency.
But you can still share code between your main project and your background agent. Just create a third project, of type "class library", and reference it from both the main project and the background agent project. Then put the shared code in that additional project.
I am developing a Standard EXE Project for sending mail.
I have a class module for sending email using winsock.
I have a withevents winsock variable set to the winsock control of a form.
The problem is that events are being catched in form's control event handler.
When i comment form's control event handling procedures and put a breakpoint in class module witheevents variable's event handler,i am unble to catch the events.
Please suggest a workaround.
If you really need to create a class (little c) that wraps constituent controls you create a UserControl, which can be invisible at runtime and have no UI interaction at all. Then, as the Winsock control's container, this UserControl will receive the events and you can handle them there.
I do this fairly often in order to create higher-level communication components, moving things like a message framing protocol inside. Then the container I put these UserControls onto only handles events raised when it has received complete messages for example. I've done the same thing to create an embeddable HTTP Server control, raising events back to the containing Form to process GET/POST requests with parameters and so on to provide a Web UI.
A Class (big C), Form, and UserControl are just three kinds of class (little c) you can create in VB6. "Class modules" really should have been called "UserClass" for clarity I suppose, in hindsight.
Like the title says, i want to disable images, and ActiveX Controls in the vb6 webbrowser control using DLCTL_NO_RUNACTIVEXCTLS and DLCTL_NO_DLACTIVEXCTLS
Microsoft talk about it here: http://msdn.microsoft.com/en-us/library/aa741313.aspx
But i dont see any way to access IDispatch::Invoke from the vb6 application.
Any help would be greatly appreciated.
I do not think VB6 let you to add the ambient properties. Try host the ActiveX in another container (e.g. an ActiveX host written by yourself - but I do not know how much time you want to invest to declare VB-friendly OLE interfaces and implement them - or use another ActiveX like the one at http://www.codeproject.com/KB/atl/vbmhwb.aspx instead.
You don't access IDispatch::Invoke in VB6, you just write you method and IDispatch is automagically implemented.
Public Function DlControl() As Long
DlControl = DLCTL_NO_DLACTIVEXCTLS Or ...
End FUnction
Then just open Tools->Procedure Attributes and for DlControl function open Advanced and assign Procedure ID to -5512 (DISPID_AMBIENT_DLCONTROL). That's first part.
Second part is to set the client site to you custom implementation of IOleClientSite. You'll need a custom typelib, try Edanmo's OLELIB for declaration of these interfaces.
Here is a delphi sample how to hook your implementation of IOleClientSite. Apparently you'll alse have to call OnAmbientPropertyChange at some point.
I'm developing an ActiveX EXE that exposes an specific class to a third-party software. This third-party software instanciates an object of this class and uses its methods.
Strangely, this third-party software destroys its object of my exposed class as soon as it calls an specific method, but I have no idea why this happens.
The only clue I have is that this method is the only one that returns a value. All the other ones are simple 'subs' that do not return any value, and when they are called nothing wrong happens.
I'm using VB6.
Do you guys have any idea of why it's happening?
Your object gets "destroyed" when the last reference to it is deleted. Thats normal COM behavior. Or is your object dying unexcepted and the third-party app is getting an activex error?
Some more questions:
I don't know what you mean with "data server"?
Do you have access to the source code of the third-party app?
Are you sure, the third-party app holds a reference to your object?
Is your objects Class_Terminate Method called?
EDIT:
OK, when Class_Terminate is getting called its obvious, that the third-party app has dropped its reference to your object.
As Jan stated in COM it is normal, that your object is terminated if no one is referencing it. If you would like to do some kind of caching (e.g. keep the DB connection open), you can use a global variable defined in a bas-module.
basGlobal.bas
Global AGlobalVariable As Object
Connector.cls
Public Function GetFoo() As Object
If AGlobalVariable Is Nothing then
Set AGlobalVariable = ...
End If
Set GetFoo = AGlobalVariable
End Function