pb中不仅可以调用com(请参见) ,也可以创建com。
创建方法:
1, 创建一个workspace
2, 在workspace下创建一个application ( 假设名字为:myapp)
3, 创建custom class,
在custom class 中可以创建 function
4, 创建 project
要选择 COM/MTS/COM+ Component Wizard
填写 Project 名
选择一个 custom class
设置 Interface Name
设置 Program ID string
默认是 PB90.[custom class 的名字],我们可以修改(假设修改为PB90.cus_class7 ,这个名字就是在pb中调用时的类名)
设置 Com Class Name
默认为COClass_[custom class的名字] (假设为COClass_cus_class7 ,这个名字就是在vb中调用时的类名)
将 Register Components Upon Successful build 选中
5, 生成dll
选中新创建的project,点击右键,然后点击Deploy
这样就完成创建com的工作。
调用方法:
1,vb中
myapp.dll
注意红字部分,为输出的dll文件名,一般和application名义相同。
写代码:
 
Dim 
   a  
  As 
    
  new 
   myapp.COClass_cus_class7
   
  MsgBox 
   a.dog
显然是通过   [application name].[Com ClassName]  来使用这个com。
2,pb中
 
int      intValue   
oleobject   objOle   
objOle   = 
  create   OLEObject   
intValue   = 
  objOle.connecttonewobject( 
  " 
  PB90.cus_class7 
  " 
  )
   if 
   intValue 
  = 
  0 
    
  then 
  
       string 
   v
    v   = 
  objOle.dog()
    Messagebox(   " 
  ss 
  " 
  ,v)
   end 
    
  if
显然是通过 [Program ID String] 来使用这个com的。
通过测试发现在vb和在pb中的调用方法是不一样的。









