15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Using OLE in console apps? possible?

Nikhil Kothari -- nkothari@nerva.ICS.UCI.EDU
Saturday, October 12, 1996

Environment: Win 95, Win NT, VC++ 4.0+

Hello All,

	I have to write an application that will be a console app (used as a
	cgi program) that will have to call OLE functions such as CoInitialize
	etc.

	I am wondering if using OLE is possible in console apps. I would like
	to know if this can be done so that I can design the app with some
	solid information.

	I would also like to know if I can use MFC's OLE support. I assume
	that I would call AfxOleInit in my main() function and then could
	use COleDispatchDriver derived classes. Again I'd like to find out
	if this can be done for sure.

Thanks in advance,
Nikhil Kothari



Mike Blaszczak -- mikeblas@nwlink.com
Sunday, October 13, 1996

At 09:23 10/12/96 -0700, Nikhil Kothari  wrote:
>Environment: Win 95, Win NT, VC++ 4.0+

What does "VC++ 4.0+" mean?  What does the extra "+" mean?

>	I am wondering if using OLE is possible in console apps.

Yes.  You don't specify which part of OLE you mean to use, but:

If you mean to use OLE automation or OLE COM objects, you can do so.
You might need to add a message pump to your console applciation because
OLE is dependant on having a message pump in some circumstances.  The most
notable, in this situation, is when marshalling calls for thread-safety
across objects with disparate thread-model implementations.  The next
notable situation are objects that end up creating windows and therefore
need a message pump anyhow.

If you really mean OLE embedding, you'll probably find that you can still
get it to work but you'll need to dork with the implementation of your
application at an expense of great pain.  That is, you'll need to write
code to give your application a message pump, and you'll also start to
pop up windows so that you have a window which can be used as the target
of the embedding.  Since you mean to write a server-side application,
it's hard to understand why you'd want to write an applicaiton with a user
interface.

>I would also like to know if I can use MFC's OLE support.

>From this, you should see that it would be easy to use COleDispatchDriver
but not so easy to use COleDocument and it's derivatives.

> I assume that I would call AfxOleInit in my main() function

If you initialize the rest of MFC first, yes.  There's a KB article
on all this.

> and then could use COleDispatchDriver derived classes.

Yep.

> I have to write an application that will be a console
> app (used as a cgi program) 

The DUMPSOME sample on my web page uses MFC and the DAO SDK classes to
write a CGI extension that spits back some database records.  DAO is,
after all, a bunch of COM objects, so this sample should be the pudding
of proof for your question.

.B ekiM
http://www.nwlink.com/~mikeblas/
Don't look at my hands: look at my _shoulders_!
These words are my own. I do not speak on behalf of Microsoft.





| Вернуться в корень Архива |