I am creating an Outlook Automation App using Ms Access. My question is: Is it possible to add references during runtime? How can this be done?
Yes, instead of saying
new Outlook.Application
Say
CreateObject("Outlook.Application")
This switches it from early binding to late binding. A little slower, but it will work fine.
If you want intellisense to work properly, use early binding (the first form) while you are coding, and then switch it to late binding (the second form) when you are done.
Related
we have a pretty big application based on paradox / objectpal. since we moved the database from filebased tables (paradox) to ms sql 2008 express edition, we encounter lots of general protection violations (GPV) which appear sporadically. these errors seem to occur only with the paradox runtime, not with the developement edition, making debugging impossible. we did a lot to minimize those GPVs and it looks like its getting better. anyway, here and there are still annoying GPVs that crash the whole application.
so, what i´m looking for is kind of a debugger / logger for windows, to see what operations / methods cause these errors. like the windows event log, but with more details that could give a hint what and where to look for. i´m not sure if such a tool even exists... .
I can think of two things you might try.
(1) Check with these guys
http://pnews.thedbcommunity.com/cgi-bin/dnewsweb.exe
on the subject of GPV (GPF) with the runtime but not with the development platform. I'm sure the your question has come up there already.
Try searching the newsgroups first, but if that fails, your question probably belongs under "pnews.paradox-development".
(2) Add logging code to the application itself. Add a library object to encapsulate an event log file, with a custom method to report an event.
Begin with a call from the open() and close() events of each design object (form, script, report, etc). Then add a call to the action() method of any suspicious objects to detect and log specific actions.
This is tedious, I know, because you have to add the library to the Var() and Open() methods of every design object in the application. But if it is done correctly, the operation of your application becomes amazingly transparent.
If an application invokes and activates another application there can be the issue of the invoked application not being brought to the foreground.
One work-around is to set the HKCU\Control Panel\Desktop\ForegroundLockTimeout registry value to 0 instead of the default 200000 milliseconds.
How should an application be controlling this registry value? Would it be feasible to temporarily change it to achieve the work-around and then change it back?
Hacking the registry on the fly is never an acceptable workaround. If an application owns the foreground window then it won't have any trouble activating the window of another application. It can be done explicitly with the AllowSetForegroundWindow() winapi function. The linked MSDN page also lists the exact rules. Also helps to find the SPI_SETFOREGROUNDLOCKTIMEOUT argument for the SystemParameterInfo function.
There's a dirty undocumented hack to break the rules. I won't go into great detail about it, other than mentioning that it is actually used in the .NET framework. Since most of your questions are .NET questions I'll assume it applies, you can use Microsoft.VisualBasic.Interaction.AppActivate() method. Not that easy to use btw.
Do keep in mind that users absolutely hate this kind of hack. Make sure your uninstaller is sound.
I would like know how this feature is implemented in VS - I understand it holds some sort of weak-reference to the object in the debugged-application's memory, but how exactly is it accomplished?
I know simply tracking the address (as in native code) wouldn't work, because the GC might move the object about, invalidating the address.
Thanks.
A description of it can be found here. It uses an unmanaged api.
Using VB6
At the time of executing, it showing white blank screen while it was working with database,
How to avoid the white blank screen in VB6.
WHITE BLANK SCREEN MEANS HANGING (WHEN IT WAS WORKING WITH DATABASE).
How to avoid that?
I assume you mean that the GUI won't redraw itself when executing a long-running operation. (Shouldn't actually be that visible starting with Vista, but I digress).
If your long-running operation is composed of several steps or tight loops, then you can sprinkle a call to DoEvents every once in a while to cause the form to remain somewhat responsive even when doing work.
Another option would be to migrate your long-running work into a separate thread but last I looked this wasn't exactly trivial or easily possible in VB6.
You should work with data base in separate thread, and any time-consuming operation should be run in a separate thread too. In this case your user interface won't be frozen.
I posted this as an answer to another question, but the pattern applies here as well:
VB6, on its own, is single threaded. However, you can make it somewhat multithreaded via the use of ActiveX EXE that run in their own process, yet still are tethered to the original VB6-created EXE.
What I've used in the past is the Timer object in conjunction with an ActiveX EXE. This approach will give you an ability to localize all the downloading logic in one place, control it like you control a regular object and have it run in a separate EXE, thus by default making it multi-threaded.
So the way this works is like so:
You call the LongRunningOperation method on the ActiveX EXE object
In the LongRunningOperation method, you instantiate the Timer and have it kick off almost immediately.
You get out of the LongRunningOperation method, thus giving control back to the entity that called it.
Then you communicate back to the main app via Events (e.g. LongRunningOperationProgress or LongRunningOperationComplete, etc...)
I recommend the Timer object from Karl Petersen.
This is actually the same problem as your "How to exit the program immediately" question. In both cases, the problem is that your database operation is blocking the VB6 program from executing.
The answer you accepted for the other question - use ADO to carry out the operations asynchronously - will also solve this blank screen problem.
Or if you prefer, follow one of my suggestions in my answer to your other question and use a .NET background worker component through Interop like this.
Or follow my other suggestion and delegate the database work to an ActiveX exe like this. EDIT AngryHacker's nice answer to this question uses this method.
Your first instinct should be to put your resource-intensive operations in a separate thread. This is a bit difficult in VB6, although possible (but not recommended) if you invoke the native CreateThread API.
You can also migrate to VB.NET, and use Thread objects natively.
I have a little problem with visual basic 6 project. Everything works fine in the IDE
but the executable crashes every time, when I run the application. The application uses callbacks to communicate with a C++ dll. Even code as simple as showing a message box fails when the callback starts.
I changed the compilation mode to P-Code and still the problem persist.
Any help would be appreciate.
Thank you all
This sounds like the callbacks may be occurring on a different thread than your application is executing on. [EDIT: As I see Jim has already suggested.] If that's the case, yeah, kaboom just as soon as you "touch" anything OLE related or call into the runtime. Same story as with multimedia timer callbacks, fwiw, and I'd suspect you'll have to take the same precautions as one would with those if this is the case.
The short story with different thread callbacks is that you'll need to post a message to yourself, using PostMessage declared in a typelib so that the Err object isn't set by VB, then let the callback return. You do your own processing on receipt of the posted message. Here's the typelib I used for this with the CCRP Timers library:
http://vb.mvps.org/tools/files/postmessage.zip
Hope that helps...
Who's calling back to whom? Show us a little code.
The IDE can mask real problems, so just being able to run there is no guarantee that what you're doing is supported.
One common problem with callbacks is that VB6's runtime is not thread-safe, so if another thread is calling back into your VB code, you can't do anything that will invoke the runtime -- like access strings or objects.
There are ways around some of these issues, but I think we need to know more first.
Is the code being run from the same location as the IDE? Likely it is a reference problem, and you need to re-register the DLL.
A deployment package should make sure you have everything installed.
A few questions:
Is the executable on the same PC as it was developed, or a different one?
Does the file use a manifest file? If so, does mainfest call XP themes?
Also, if using manifest, does manifest use SXS for OCX files?