.Net Forms application, File and FolderDialogs

G

Guest

Hi there,

We have a C++/CLI .NET 2 forms based application where the .NET forms front
end lives in an ATL server solution, and uses COM to talk with a separate
back end process.

For development, the executable was built as a pure .NET solution
incorporating all the back end code, and worked well. We then migrated to
the final architecture which has thrown up a couple of issues.

The main problem is this. In a few places we have FileDialogs
(OpenFileDialog and SaveFileDialog instances) as well as FolderBrowserDialog
instances. These worked fine in the .Net solution, but in the ATL solution,
cause a ThreadStateExceptions and state the main function should have an
STAThreadAttribute applied. We can't set this attribute since we're running
from an ATL server. We have however tried changing the CoInitialize call to
CoInitializeEx and specifying Apartment Threading, as well as hacking the
stdafx.h macro to be _ATL_SINGLE_THREADED. All to no avail.

The other issue is more minor but still annoying. The look and feel has
changed slightly from the pure .Net based solution. Colours are slightly
different and some button text falls off the right of the button (perhaps due
to different fonts or font sizes). Any ideas as to why this is / how to fix
it (I'd rather not check/resize all the buttons!) would also be good.

Any help much appreciated!

Regards,
Ed
 
G

Guest

Hi All,

Dubious form to follow up yourself I know, but I've found the answers...

The STA issue looks like it occurs as, since the solution contains both
managed and unmanaged, it is kicked off via mscorwks which does a
CoInitialise/CoInitialiseEx for you rendering the one in my ATL server main
useless (it returned the CHANGED_MODE failure). It is easily solved however
when you finally locate and set the "CLR Thread Attribute" setting in the
Linker->Advanced settings for the project to STA.

The look and feel / text length issue is down to needing calls to
EnableVisualStyles() and a SetCompatibleTextRenderingDefault(false) which get
put in the main function that Studio creates for a pure WinForms solution,
but weren't in mine since I didn't have the WinForms main any longer.

Hope this helps someone in future.

Regards,
Ed
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top