通过Windows Forms应用程序连接到ATL [英] Connecting to ATL through a Windows Forms Application

查看:89
本文介绍了通过Windows Forms应用程序连接到ATL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好.

环境:Visual Studio2008.语言:C ++

(这正在演变为一个两部分的问题,我希望这是允许的...)

我有一个ATL项目,我正在努力替换一个较旧版本(我相信是VC ++ 6,尽管似乎没人非常确定)中开发的现有工具.

我已经使用向导创建了ATL服务(IScribe),并已通过控制台应用程序连接到该服务,并且已经迁移到Windows Form客户端,以便允许我扩展测试环境(并作为将来的概念证明)服务的潜在用途).

我已经在表单中添加了:

Good day.

Environment: Visual Studio 2008. Language: C++

(This is evolving into a two part question, I hope that''s permitted...)

I have an ATL Project that I am working to replace an existing tool developed in an older version (VC++6, I believe, although nobody seems terribly sure).

I have created the ATL service (IScribe) using the wizard and have connected to it via a console application and have been moving to a Windows Form client in order to allow me to extend the testing environment (and as a proof of concept on a future potential use for the service).

I have added to the form the :

IIScribeServer* ISS;


在Form1_Load中,我有以下代码:


and in the Form1_Load, I have the code:

BSTR message = NULL;           //for capturing the return message from server
HRESULT hr;                    //COM error code;
hr = CoInitialize(0);
if(SUCCEEDED(hr))  //hr succ 1
{       hr = CoCreateInstance(
        CLSID_IScribeServer,
        NULL,
        CLSCTX_INPROC_SERVER,
        IID_IIScribeServer,
        (void**) &ISS);
    if(SUCCEEDED(hr))  //hr succ 2
    {
        long f5 = 5;  //meaningless numbers, just proving can store and return
        long f11 = 11;
        //Call to get pseudo version information from server and display to form
        hr = ISS-> GetCaption(&f5,  &f11 , &message);

        this->Text =  gcnew System::String(message);

        message = NULL; //had a ::SysFreeString(*message), but it would fail
     } //hr succ 2
 }//hr succ 1



问题1:
如果我在Form1_Load事件中声明IIScribeServer,它将正常工作.
如果按此代码的形式在Form级别上声明它,则会收到错误C2440:类型转换"无法从"cli :: interior_ptr< type>"转换为"void **"".
我会在这里缺少什么来进行转换?

解决方法:我添加了一个中间调用以允许创建



Question 1:
If I declare the IIScribeServer within the Form1_Load event, it works fine.
If I declare it at the Form level, as in this code, I receive "error C2440: ''type cast'' cannot convert from ''cli::interior_ptr<type> to ''void**''".
What would I be missing here to allow the conversion?

As a workaround: I added an intermediary call to allow the creation

BSTR message = NULL;                //used to accept return value from server.
IIScribeServer *ISSb;    //pointer to the interface
HRESULT hr;              //COM error code;






and

if(SUCCEEDED(hr))  //hr succ 1
    {       hr = CoCreateInstance(
            CLSID_IScribeServer,
            NULL,
            CLSCTX_INPROC_SERVER,
            IID_IIScribeServer,
            (void**) &ISSb);      //Changed HERE
if(SUCCEEDED(hr)) //hr succ 2
{

    ISX = ISXb;

    ISXb = NULL;



而且所有的作品都符合我的期望.

在按钮上单击表格,我确实拨打了



And all works as I expect.

In a button click on the form, I do make a call to

HRESULT hr;
			LONG  puHi, puLo;
			puHi = Convert::ToInt32(this->textBoxHighPart->Text);
			puLo = Convert::ToInt32(this->textBoxLowPart->Text);
			hr = ISS ->GetTimeStamp(&puHi, &puLo);
			this->textBoxHighPart->Text = Convert::ToString((__int32)puHi);
			this->textBoxLowPart->Text = Convert::ToString((__int32)puLo);





The

CoUninitialize()

的格式为close.
它将发送文本框的值并对其进行次要数学运算(加一,再除其他),并替换文本框.没什么.

这可以正常工作,并且可以在调试中进行编译...但不能在Release中进行编译.


问题2:Gu?我不确定从哪里开始,但是它没有内置在Release中.
(第二季度已解决...
添加了

is on the form close.
Which sends the values of the text box and performs minor math (add one, sub other) on them and replaces the text box. Nothing big.

This works fine and compiles in debug... but not in Release.


Question 2: Guh? I''m not sure where to start, but it doesn''t build in Release.
(Q2 is SOLVED...
added a

#pragma comment ( lib, "ole32.lib" ) //to link the ole32 library

然后就解决了.
)

在输出"窗口中:
1> -------构建开始:项目:InfWindow,配置:Win32版本------
1>正在链接...
1> InfoWindow.obj:错误LNK2001:无法解析的外部符号"extern"C" long __stdcall CoInitialize(void *)(?CoInitialize @@ $$ J14YGJPAX @ Z)
1> InfoWindow.obj:错误LNK2001:未解析的外部符号"extern"C" long __stdcall CoCreateInstance(struct _GUID const&,struct IUnknown *,unsigned long,struct _GUID const&,void * *)"(?CoCreateInstance @@ $$ J220YGJABU_GUID @@ PAUI未知@@ K0PAPAX @ Z)
1> InfoWindow.obj:错误LNK2001:无法解析的外部符号外部"C" void __stdcall CoUninitialize(void)(?CoUninitialize @@ $$ J10YGXXZ)
1> C:\ dev \ Visual Studio 2008 \ Projects \ IScribe \ Release \ InfWindow.exe:致命错误LNK1120:3个未解决的外部组件


(无论IScribeServer * ISS;在窗体级别还是Form1_Load级别,都会发生这些错误)

不得不将对象重命名为IScribeServer等,以便在这里不会出现一些假发,如果在换出这些代码的代码中出现转置错误,我们深表歉意.

at the top and that took care of it.
)

From the Output window:
1>------ Build started: Project: InfWindow, Configuration: Release Win32 ------
1>Linking...
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall CoInitialize(void *)" (?CoInitialize@@$$J14YGJPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@$$J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" void __stdcall CoUninitialize(void)" (?CoUninitialize@@$$J10YGXXZ)
1>C:\dev\Visual Studio 2008\Projects\IScribe\Release\InfWindow.exe : fatal error LNK1120: 3 unresolved externals


(these errors occur whether the IScribeServer * ISS; is at Form level or Form1_Load level)

Had to rename the objects to IScribeServer etc... in order to not flip some wigs here, apologies if transposition errors in teh above code in making those swap outs.

推荐答案

J14YGJPAX @ Z)
1> InfoWindow.obj:错误LNK2001:未解析的外部符号"extern"C" long __stdcall CoCreateInstance(struct _GUID const&,struct IUnknown *,unsigned long,struct _GUID const&,void * *)"(?CoCreateInstance @@
J14YGJPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" long __stdcall CoCreateInstance(struct _GUID const &,struct IUnknown *,unsigned long,struct _GUID const &,void * *)" (?CoCreateInstance@@


J220YGJABU_GUID @@ PAUIUnknown @@ K0PAPAX @ Z)
1> InfoWindow.obj:错误LNK2001:无法解析的外部符号外部"C" void __stdcall CoUninitialize(void)(?CoUninitialize @@
J220YGJABU_GUID@@PAUIUnknown@@K0PAPAX@Z)
1>InfoWindow.obj : error LNK2001: unresolved external symbol "extern "C" void __stdcall CoUninitialize(void)" (?CoUninitialize@@


J10YGXXZ)
1> C:\ dev \ Visual Studio 2008 \ Projects \ IScribe \ Release \ InfWindow.exe:致命错误LNK1120:3个未解决的外部组件

(无论IScribeServer * ISS;在窗体级别还是Form1_Load级别,都会发生这些错误)

不得不将对象重命名为IScribeServer等,以免在这里出现一些假发,如果在换出这些代码的代码中出现转置错误,我们深表歉意.
J10YGXXZ)
1>C:\dev\Visual Studio 2008\Projects\IScribe\Release\InfWindow.exe : fatal error LNK1120: 3 unresolved externals

(these errors occur whether the IScribeServer * ISS; is at Form level or Form1_Load level)

Had to rename the objects to IScribeServer etc... in order to not flip some wigs here, apologies if transposition errors in teh above code in making those swap outs.


这篇关于通过Windows Forms应用程序连接到ATL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆