设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11927|回复: 0

[求助] c++和extend的COM接口问题

[复制链接]
发表于 2008-11-25 19:37:03 | 显示全部楼层 |阅读模式
5仿真币
我现在用c++编写了一个程序,希望能够和extend交换数据,以及自动对extend进行一些操作。我参阅了例子里的关于OLE AUTOMATION方面的c++程序,但搞得不是很懂。比如说,c++程序向extend发送一个数据:6 [( D% d2 d: H; d# b0 Y6 b4 {
Name = (WCHAR *) L"Poke";
& A, M+ }5 T4 H3 j" d9 l                 9 }% f* Z$ \# Z0 Z# a
        hr = m_pDisp->GetIDsOfNames (
9 n+ x/ w+ f! @! t! u                IID_NULL,                                // reserved3 r$ X" W) x+ g
                &Name,                                        // Array of names to get IDs for
6 L4 u3 [' L7 h' f: s& a; X* t                1,                                        // # of names in the array
& s6 s. l: J3 }+ L$ p                LOCALE_SYSTEM_DEFAULT,        // System locale
6 w" `0 q! V, j' O                &pokeID);                                // Array of IDs to fill on output2 n' w2 V6 A8 W  Z* Y
                        ! W$ ?1 N* M) l3 o# R' m
        if (hr)2 b' M9 c5 p( X. x# U
                {  F, h5 w$ |9 `% Y0 p
                MessageBox ("Get Poke Unsuccessful");
  l# m& a3 o6 _' r7 a                return;
/ z# W2 J- R; m: b  e4 R! \                }
" R3 P0 ], x( a' @, p7 k, U1 @$ E
4 l) Z  @; d1 S1 D8 m/**************************传递数据给extend**************************************/; E) X* n4 ?1 B
        pokeVariant                         = (VARIANTARG *)malloc(sizeof(VARIANTARG) *3);* Z5 [  G. n7 b  u
        9 Y4 _$ \4 }; M/ C6 }! ]( V
        valueStr                                 = SysAllocString((WCHAR *) L"1232");) ]; ]& N9 [0 I6 Y4 m6 W
        VariantInit(&pokeVariant[0]);
4 d  f+ c/ O0 {/ `1 Z4 K        pokeVariant[0].vt                 = VT_BSTR;/ Y% D, S7 T6 s4 ~* Z4 k0 N
        pokeVariant[0].bstrVal         = valueStr;# B/ \1 ~; [; J. c$ `8 D1 O8 ~

3 h7 r9 R1 n% J" u  L         itemStr                                 = SysAllocString((WCHAR *) L"global0:#0:0:0:0:0");9 e, y! H* Q8 G9 i$ S4 |1 x
        VariantInit(&pokeVariant[1]);
- A( ?; I5 U( F- t/ B( ?# a        pokeVariant[1].vt                 = VT_BSTR;& y8 [, O% L* n2 L1 [# [" m
        pokeVariant[1].bstrVal         = itemStr;
, ~1 ?# d9 ~# ^3 o, L; Q% f5 Y4 E
# j/ Q. W2 g: w9 h. Y& ?6 Y' ?8 B          topicStr                                 = SysAllocString((WCHAR *) L"system");9 u, B! w, [0 P# ~( h* g% G& Q
        VariantInit(&pokeVariant[2]);   s9 V  e; a: [0 N! d7 e4 \
        pokeVariant[2].vt                 = VT_BSTR;
7 h. C1 Q# `6 N; h$ x; T8 g% U$ u& T        pokeVariant[2].bstrVal         = topicStr;
2 u3 j; ~$ c$ r
7 a; u' K' W) Y2 S! M- R1 G; Z1 B3 w; ^//        Set the DISPPARAMS structure that holds the variant." v, N6 Y7 a, N/ W. [2 k2 ^
# R0 c" I# p- H2 a3 ]+ T6 S0 w
        dp.rgvarg                                         = pokeVariant;% y) ]' z4 W& e4 A' c" w/ l
        dp.cArgs                                         = 3;
+ m; _0 G4 b" W# k        dp.rgdispidNamedArgs                 = NULL;' x8 T8 R( Y4 s* F
        dp.cNamedArgs                                 = 0;# k- `+ C( t% x! ?8 Z6 c( G+ W

5 i0 `" c# }; m- w: h//        Call IDispatch::Invoke()) `" U1 G/ g' {/ _6 o9 c

5 |# G2 y- [# p: y. g" H        hr = m_pDisp->Invoke(
0 }/ [0 f6 v, j; `- ?                pokeID,( A, d) A( s! d% Q, ]
                IID_NULL,  D5 t3 t, t2 w' D2 N7 l0 p& q! E
                LOCALE_SYSTEM_DEFAULT,
) k, T6 U$ M6 ?3 a( }( g                DISPATCH_METHOD,2 r! \1 d6 n8 F, |
                &dp,
: A7 v8 s7 P) ?' U" h                NULL,% I1 M/ O- |4 a7 j; _0 t
                &ei,
2 [9 i& Q  K. j# R2 N                &uiErr);/ D# x* e3 |" S+ ^/ W5 G0 x2 Q

' X5 Y# W0 O; w: h; v0 s; W- e        SysFreeString(topicStr);
$ Y+ b& `4 H; ]) p9 \- r        SysFreeString(itemStr);+ g/ R3 N) F8 N# P7 u9 I
        SysFreeString(valueStr);  A% }1 d  y% A: V* y4 a7 j% G

; j; w1 M' v% }% n现在这个程序可以实现将1232这个数据发送到extend,extend有一个对话框弹出并出现1232这个数据,不知道这个对话框为什么会弹出并显示这个数据???
0 g$ Q3 R( l4 _7 Y, Q6 h& {" H此外我希望将这个数据赋给extend程序里面的一个变量,请问如何实现????
1 _( v2 i$ G* L6 A7 M. w$ T# Q
) y- t: P% @" q0 p1 }6 o* i& f; J; }& V' ]- w9 m
2.这是request的程序& y: c* g* c& g
//  Request a value from Extend2 Q6 R" w4 S+ v# k: R
//! x. E& N8 `; R0 u% Q3 s3 y+ D
//        Initialize the variant that will hold the BSTR.  Set the variant's+ O4 [. J' u- s
//        type flag to indicate the fact that this variant holds a BSTR. Place the8 v9 |. i! h% E3 J
//        BSTR into the variant structure.( q4 i5 D1 g  @+ Y3 c. [+ S) G, p

  S. N$ M) v+ {& s: n  O        requestVariant                                 = (VARIANTARG *)malloc(sizeof(VARIANTARG) *2);6 M) ~$ k. H" T; ?
       
! d) }: @- Z5 F4 Q: B: X         itemStr                                         = SysAllocString((WCHAR *) L"global0:#0:0:0:0:0");
  E& M% i  d, f/ I9 R        VariantInit(&requestVariant[0]);
" D5 f1 ~- G8 ^6 g) G        requestVariant[0].vt                 = VT_BSTR;
+ ]6 e% q6 x8 }/ L        requestVariant[0].bstrVal         = itemStr;3 F3 c+ {( K3 I$ |, G& n

' o- l5 W+ t0 u  x: `# F          topicStr                                         = SysAllocString((WCHAR *) L"system");$ j" P' |! N3 H! G0 J
        VariantInit(&requestVariant[1]);
3 u; }) r, `/ |+ k! w        requestVariant[1].vt                 = VT_BSTR;5 l3 H/ |! c: i5 p/ y2 e
        requestVariant[1].bstrVal         = topicStr;
' _8 P/ D/ d: z1 y9 p$ S2 H( `7 D0 ]# j: I- U
//        Set the DISPPARAMS structure that holds the variant., I% _& C  W! D- W5 J
; ^' p6 Z9 b' [, |$ Y
        dp2.rgvarg                                         = requestVariant;
$ U( w3 c$ l5 e6 J" n* t1 j) D        dp2.cArgs                                         = 2;
: ~0 U7 `% ]) t0 w* r5 u        dp2.rgdispidNamedArgs                 = NULL;' [/ o( f+ i+ u" x+ z
        dp2.cNamedArgs                                 = 0;
8 a8 c; K2 R" b! L4 T7 U3 l! n1 Q8 S$ o$ f$ {0 _
        var.vt = VT_EMPTY;! Z8 w  G& H( i7 H0 }3 c  m6 u: T5 ?

( {8 c# P( Q0 T4 r/ m% _//        Call IDispatch::Invoke()8 d! C1 F- C% D5 U- f

2 P) f6 T+ m4 Q* O+ Q# \        hr = m_pDisp->Invoke(3 f3 K9 K' ~4 y1 O3 B3 J- f0 \% L) q7 p
                requestID,
8 E# P$ c# c' r+ g                IID_NULL,
) [. P9 U3 p8 k5 x                LOCALE_SYSTEM_DEFAULT,; {5 p( _. j  V1 V" L
                DISPATCH_METHOD,
, V9 G* a6 [7 H3 Q                &dp2,
( Y. N+ y9 U, [  T                &var,9 v# u' o* Z1 j4 l! o4 K& y
                &ei,( }  I  `4 |0 J5 g, `
                &uiErr);0 A5 W4 t7 z) a# ^# Z" J; D  s) ?

0 @9 a8 R' U) a* e2 A8 p2 y5 z        SysFreeString(topicStr);. O1 a7 T$ X" d: N1 A, t( i
        SysFreeString(itemStr);/ b' A% w- b# Z2 k% S& ]+ n
请问该程序是获得extend里面的哪个值?: M6 [% J+ ]6 z- e' S. l) U
如果我希望获得extend程序里面的某个变量的数值,那个c++程序应该如何实现????

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-7-25 08:23 , Processed in 0.012550 second(s), 12 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表