📄 如何在vc++中调用标准com组件.mht
字号:
id=3Dgsfx_bsrch_websrchbtn =
onclick=3D"submitSimpleSearch('http://search.live.com/results.aspx?mkt=3D=
zh-cn&q=3D', document.getElementById('gsfx_bsrch_query').value);" =
type=3Dbutton =
value=3D=E6=90=9C=E7=B4=A2=E4=BA=92=E8=81=94=E7=BD=91></SPAN><BR></DIV>
<SCRIPT =
type=3Dtext/javascript>try{MS.Support.AC.MakeAutoComplete({id:'gsfx_bsrch=
_query', lcid:'2052', acURL:'http://autocomplete.support.microsoft.com', =
statsObj:StatsDotNet, startChar:'4', =
bubbleside:'left'});}catch(e){}</SCRIPT>
<DIV class=3Dgsfx_brnd_NetworkTextRight =
id=3Dgsfx_bsrch_poweredbycell><SPAN>powered=20
by</SPAN><SPAN id=3Dliveimg><IMG class=3Dgsfx_img_png=20
style=3D"WIDTH: 24px; HEIGHT: 24px" alt=3D""=20
src=3D"http://support.microsoft.com/library/images/support/en-US/gsfx_bsr=
ch_live_logo.png"><!--[if lte IE 6]><div alt=3D"" class=3D"gsfx_div_png" =
style=3D"width:24px;height:24px;filter:progid:DXImageTransform.Microsoft.=
AlphaImageLoader(src=3D'/library/images/support/en-US/gsfx_bsrch_live_log=
o.png', =
sizingMethod=3D'scale');"></div><![endif]--></SPAN><SPAN>Live=E6=90=9C=E7=
=B4=A2</SPAN>=20
</DIV>
<DIV class=3Dhiddenformels><INPUT type=3Dhidden value=3Dr name=3Dmode> =
</DIV><NOSCRIPT>
<STYLE type=3Dtext/css>#gsfx_bsrch_catsel A {
DISPLAY: none
}
#gsfx_bsrch_websrch {
DISPLAY: none
}
</STYLE>
</NOSCRIPT></FORM>
<SCRIPT type=3Dtext/javascript>
InitSrch();
InitAC('gsfx_bsrch_query');MS_AddEvent(window, 'load', function() =
{gsfx_bsrch_InitCatSelection('gsfx_bsrch_query', '4:4:');});
</SCRIPT>
</DIV></DIV></DIV>
<DIV class=3Dgsfx_brnd_CornerContainer id=3Dgsfx_brnd_TopCorners>
<DIV class=3D"gsfx_brnd_TBBorders gsfx_brnd_TransBG" =
id=3Dgsfx_brnd_TopBorder></DIV>
<DIV class=3Dgsfx_brnd_Corner id=3Dgsfx_brnd_LUpperCorner></DIV></DIV>
<DIV class=3D"gsfx_brnd_TransBG gsfx_brnd_SideBorder" =
id=3Dgsfx_brnd_LocalToolBar>
<UL id=3Dgsfx_brnd_LocalLinks>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_156473=20
=
href=3D"http://support.microsoft.com/"><SPAN>=E5=B8=AE=E5=8A=A9=E5=92=8C=E6=
=94=AF=E6=8C=81=E9=A6=96=E9=A1=B5</SPAN></A></LI>
<LI class=3Dgsfx_brnd_LocalSeperator></LI>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_156474=20
=
href=3D"http://support.microsoft.com/select/?target=3Dhub"><SPAN>=E9=80=89=
=E6=8B=A9=E4=BA=A7=E5=93=81=E6=94=AF=E6=8C=81=E4=B8=AD=E5=BF=83</SPAN></A=
></LI>
<LI class=3Dgsfx_brnd_LocalSeperator></LI>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_156475=20
=
href=3D"http://support.microsoft.com/search/?adv=3D1"><SPAN>=E9=AB=98=E7=BA=
=A7=E6=90=9C=E7=B4=A2</SPAN></A></LI>
<LI class=3Dgsfx_brnd_LocalSeperator></LI>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_159742=20
=
href=3D"http://support.microsoft.com/gp/downloadover/zh-cn"><SPAN>=E4=B8=8B=
=E8=BD=BD=E4=B8=8E=E6=9B=B4=E6=96=B0</SPAN></A></LI>
<LI class=3Dgsfx_brnd_LocalSeperator></LI>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_171632=20
=
href=3D"http://support.microsoft.com/gp/bbsindex/zh-cn"><SPAN>=E7=A4=BE=E5=
=8C=BA=E6=88=96=E8=AE=BA=E5=9D=9B</SPAN></A></LI>
<LI class=3Dgsfx_brnd_LocalSeperator></LI>
<LI class=3Dgsfx_brnd_LocalLink><A id=3DL_168698=20
=
href=3D"http://support.microsoft.com/contactus/?ws=3Dsupport"><SPAN>=E8=81=
=94=E7=B3=BB=E5=BE=AE=E8=BD=AF</SPAN></A></LI></UL></DIV>
<DIV class=3D"gsfx_brnd_TransBG gsfx_brnd_SideBorder" =
id=3Dgsfx_brnd_ToolbarShadow>
<DIV id=3Dgsfx_brnd_shadow></DIV></DIV>
<DIV class=3D"gsfx_brnd_TransBG gsfx_brnd_SideBorder"=20
id=3Dgsfx_brnd_ContentContainer>
<DIV id=3DcontentArea>
<DIV id=3DmainRow>
<DIV class=3DprimaryTable>
<TABLE class=3DprimaryTable cellSpacing=3D0 cellPadding=3D0>
<TBODY>
<TR>
<TD class=3DprimaryMainColumn>
<DIV lang=3Den-us id=3DmainColumn>
<DIV class=3Dkb id=3Dkb>
<DIV class=3Ddefault id=3Ddefault><!-- - -KB 3 start- - --><A =
id=3Dtop></A>
<H1 class=3Dtitle>How to access a Visual Basic ActiveX DLL from a =
Visual C++=20
6.0 executable</H1>
<DIV class=3DappliesToLink><A=20
=
href=3D"http://support.microsoft.com/default.aspx?scid=3Dhttp://support.m=
icrosoft.com:80/support/kb/articles/Q194/8/73.ASP&NoWebContent=3D1#ap=
pliesto">View=20
products that this article applies to.</A></DIV>
<SCRIPT type=3Dtext/javascript>function loadTOCNode(){}</SCRIPT>
<DIV class=3DarticleProperty>
<TABLE>
<TBODY>
<TR>
<TD>Article ID</TD>
<TD>:</TD>
<TD>194873</TD></TR>
<TR>
<TD>Last Review</TD>
<TD>:</TD>
<TD>June 2, 2005</TD></TR>
<TR>
<TD>Revision</TD>
<TD>:</TD>
<TD>5.0</TD></TR></TBODY></TABLE></DIV>
<DIV class=3Dnotice>This article was previously published under=20
Q194873</DIV>
<DIV class=3Dtoc id=3DtocDiv>
<H5>On This Page</H5></DIV>
<SCRIPT type=3Dtext/javascript>=0A=
var sectionFilter =3D "type !=3D 'notice' && type !=3D =
'securedata' && type !=3D 'querywords'";=0A=
var tocArrow =3D =
"/library/images/support/kbgraphics/public/en-us/downarrow.gif";=0A=
var depthLimit =3D 10;=0A=
var depth3Limit =3D 10;=0A=
var depth4Limit =3D 5;=0A=
var depth5Limit =3D 3;=0A=
var tocEntryMinimum =3D 1;=0A=
</SCRIPT>
<SCRIPT =
src=3D"http://support.microsoft.com/common/script/gsfx/kbtoc.js?13"=20
type=3Dtext/javascript></SCRIPT>
<NOSCRIPT>
<STYLE>.toc {
DISPLAY: none
}
</STYLE>
</NOSCRIPT>
<DIV class=3Dsection>
<H2 class=3DsubTitle id=3DtocHeadRef>SUMMARY</H2>
<SCRIPT type=3Dtext/javascript>loadTOCNode(1, 'summary');</SCRIPT>
<DIV class=3Dsbody>This article shows three ways to access a =
Visual Basic=20
ActiveX DLL from a Visual C++ 6.0 executable.=20
<P class=3DtopOfPage><A=20
=
href=3D"http://support.microsoft.com/default.aspx?scid=3Dhttp://support.m=
icrosoft.com:80/support/kb/articles/Q194/8/73.ASP&NoWebContent=3D1#to=
p"><IMG=20
alt=3D""=20
=
src=3D"http://support.microsoft.com/library/images/support/kbgraphics/pub=
lic/en-us/uparrow.gif">Back=20
to the top</A></P></DIV>
<H2 class=3DsubTitle id=3DtocHeadRef>MORE INFORMATION</H2>
<SCRIPT type=3Dtext/javascript>loadTOCNode(1, =
'moreinformation');</SCRIPT>
<DIV class=3Dsbody>This article represents an introduction to =
creating=20
Visual C++ clients for Visual Basic ActiveX components. If you are =
already=20
proficient with Visual C++, you may wish to refer to the reference =
section=20
for a list of more advanced topics. <BR><BR>
<P class=3DtopOfPage><A=20
=
href=3D"http://support.microsoft.com/default.aspx?scid=3Dhttp://support.m=
icrosoft.com:80/support/kb/articles/Q194/8/73.ASP&NoWebContent=3D1#to=
p"><IMG=20
alt=3D""=20
=
src=3D"http://support.microsoft.com/library/images/support/kbgraphics/pub=
lic/en-us/uparrow.gif">Back=20
to the top</A></P>
<H3 id=3DtocHeadRef>Steps to Create the Visual Basic Server</H3>
<SCRIPT type=3Dtext/javascript>loadTOCNode(2, =
'moreinformation');</SCRIPT>
<BR><BR>
<TABLE class=3D"list ol">
<TBODY>
<TR>
<TD class=3Dnumber>1.</TD>
<TD class=3Dtext>Create a Visual Basic ActiveX DLL project. =
Class1 is=20
created by default. </TD></TR>
<TR>
<TD class=3Dnumber>2.</TD>
<TD class=3Dtext>Add the following code to Class1: <CODE><PRE =
class=3Dcode> Public Function MyVBFunction(x As Integer) As Integer
MsgBox x
End Function
</PRE></CODE></TD></TR>
<TR>
<TD class=3Dnumber>3.</TD>
<TD class=3Dtext>Compile the DLL as c:\Project1.dll and exit =
Visual=20
Basic. </TD></TR></TBODY></TABLE>Method 1 - CreateDispatch: =
<BR><BR>
<TABLE class=3D"list ol">
<TBODY>
<TR>
<TD class=3Dnumber>1.</TD>
<TD class=3Dtext>Start Visual C++ and select New on the File =
menu.=20
Choose MFC AppWizard (Exe) and a project name, and Click OK. =
When=20
the MFC AppWizard dialog box appears, click Finish. Click OK =
on the=20
next dialog box. </TD></TR>
<TR>
<TD class=3Dnumber>2.</TD>
<TD class=3Dtext>Select ClassWizard on the View menu, pick =
Ctst1App in=20
the Class Name box, and double-click InitInstance in the =
Messages=20
box. Click Edit Code to bring up the code for BOOL=20
CTst1App::InitInstance(), find the line=20
AfxEnableControlContainer();, and add the following line =
before it:=20
<CODE><PRE class=3Dcode> =
AfxOleInit();</PRE></CODE></TD></TR>
<TR>
<TD class=3Dnumber>3.</TD>
<TD class=3Dtext>Select ClassWizard from the View menu and =
click the=20
Automation tab. Click AddClass and select "from a =
TypeLibrary".=20
Specify Project1.dll, the Visual Basic DLL which was created =
in step=20
3. When the Confirm Classes dialog box appears, click OK. =
Click OK=20
again to close the MFC ClassWizard dialog box. </TD></TR>
<TR>
<TD class=3Dnumber>4.</TD>
<TD class=3Dtext>Open your <App Name>.cpp file and add =
the line=20
#include "Project1.h". You need to include Project1.h =
wherever you=20
have code that accesses project1.dll. </TD></TR>
<TR>
<TD class=3Dnumber>5.</TD>
<TD class=3Dtext>Open the ClassWizard again. On the Message =
Maps tab,=20
select CAboutDlg in the Class Name box and IDOK in the =
Object IDs=20
box, and then double-click BN_CLICKED. Click OK in response =
to the=20
dialog box and OK again to close the ClassWizard. </TD></TR>
<TR>
<TD class=3Dnumber>6.</TD>
<TD class=3Dtext>Open <App Name>.cpp, scroll to the =
bottom to=20
theCAboutDlg::OnOK(), and replace it with the following =
code: <CODE><PRE class=3Dcode> void CAboutDlg::OnOK()
{
short st =3D 2;
short st1;
_Class1 p;
p.CreateDispatch("Project1.Class1");
st1 =3D p.MyVBFunction(&amp;st);
CDialog::OnOK();
}
</PRE></CODE></TD></TR>
<TR>
<TD class=3Dnumber>7.</TD>
<TD class=3Dtext>Compile your .exe file (F7). </TD></TR>
<TR>
<TD class=3Dnumber>8.</TD>
<TD class=3Dtext>Run the .exe file and select About on the =
Help menu.=20
Click OK on the About box and the message box that was =
specified in=20
project1.dll appears. Click the Close button to dismiss the =
dialog=20
box. </TD></TR></TBODY></TABLE>Method 2 - #IMPORT: <BR><BR>
<TABLE class=3D"list ol">
<TBODY>
<TR>
<TD class=3Dnumber>1.</TD>
<TD class=3Dtext>Start Visual C++ 6.0 and create a Win32 =
Console=20
Application. Select "An Empty Project" and click Finish. =
</TD></TR>
<TR>
<TD class=3Dnumber>2.</TD>
<TD class=3Dtext>Point to Add to Project on the Project menu =
and click=20
New to add a new C++ source file to the project. Paste the =
following=20
code in the new source file and save it: <CODE><PRE =
class=3Dcode> #include <stdio.h>
// This is the path for your DLL.
// Make sure that you specify the exact path.
#import "c:\project1.dll" no_namespace
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -