惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
博客园 - 聂微东
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
罗磊的独立博客
H
Help Net Security
L
LangChain Blog
T
Threat Research - Cisco Blogs
量子位
S
Securelist
Last Week in AI
Last Week in AI
L
Lohrmann on Cybersecurity
T
The Exploit Database - CXSecurity.com
P
Privacy International News Feed
The Hacker News
The Hacker News
Vercel News
Vercel News
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Blog of Author Tim Ferriss
T
Threatpost
Security Latest
Security Latest
P
Palo Alto Networks Blog
Microsoft Security Blog
Microsoft Security Blog
NISL@THU
NISL@THU
F
Full Disclosure
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Stack Overflow Blog
Stack Overflow Blog
C
Check Point Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
酷 壳 – CoolShell
酷 壳 – CoolShell
H
Heimdal Security Blog
J
Java Code Geeks
Recorded Future
Recorded Future
Hugging Face - Blog
Hugging Face - Blog
G
GRAHAM CLULEY
Know Your Adversary
Know Your Adversary
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
B
Blog RSS Feed
月光博客
月光博客
C
Cisco Blogs
V
Visual Studio Blog
D
DataBreaches.Net
H
Hacker News: Front Page
博客园 - 叶小钗
N
News and Events Feed by Topic
爱范儿
爱范儿
A
Arctic Wolf

博客园 - 懒蜜蜂

身份证校验规则 [转]扩展jQuery easyui datagrid增加动态改变列编辑的类型 在IIS 5.1/6上以FastCGI方式安装 PHP 如何修复.Net和COM之间枚举名称的问题(续) 通过修改IP/TCP包头伪造IP来与网页进行交互 如何修复.Net和COM之间枚举名称的问题 Objective-C札记二-- Iphone中关于Layer的opaque属性 Xcode配置SVN作为版本控制 Emacs快捷键 Objective C中的札记--字符串连接,@selector中的冒号,时间转换,局部变量 使用GDataXML的设置 IPhone Exec_Bad_Access问题解决办法 C#版的AMF消息封装 Javascript中暂停功能的实现 - 懒蜜蜂 - 博客园 数据库基础理论--关系模式及范式 函数依赖(转) 数据库基础理论之--超键 候选键 主键 拷贝VMWare虚机(XP操作系统)之后网络不通
Compiling and Registering a Type Library
懒蜜蜂 · 2010-12-22 · via 博客园 - 懒蜜蜂

In subsequent examples you will need to be able to compile type libraries and reference them from VB projects. In this example you will compile an IDL file using the Microsoft IDL compiler and register the resulting type library file with Windows, thereby allowing you to reference the type library in VB just like an ActiveX component. But first, you may require some essential background information. The MIDL compiler is a DOS based application. Because of this, you must make sure MIDL is running in a DOS shell with the proper environment variables set. MIDL must be able to locate additional files it requires to compile your IDL code. If your experience with DOS is limited this can be troublesome depending which Windows operating system your using and how you installed Visual Studio. So, the first few steps in this example are the steps I used to get my Windows 98 system ready to compile IDL files. If youre running Windows NT and you have properly installed the C++ portion of Visual Studio you will probably be able to go straight to step 5.

  1. Locate a file with the name VCVARS32.BAT, normally located in C:\Program Files\Microsoft Visual Studio\VC98\Bin\. Visual Studio will have already included this file during installation. The contents of the batch file should look like this:

@echo off

rem
rem Root of Visual Developer Studio Common files.
set VSCommonDir=C:\PROGRA~1\MICROS~4\COMMON

rem
rem Root of Visual Developer Studio installed files.
rem
set MSDevDir=C:\PROGRA~1\MICROS~4\COMMON\msdev98
rem
rem Root of Visual C++ installed files.
rem
set MSVCDir=C:\PROGRA~1\MICROS~4\VC98
rem
rem VcOsDir is used to help create either a Windows 95 or Windows NT specific path.
rem
set VcOsDir=WIN95
if "%OS%" == "Windows_NT" set VcOsDir=WINNT
rem
echo Setting environment for using Microsoft Visual C++ tools.
rem
if "%OS%" == "Windows_NT" set PATH=%MSDevDir%\BIN;%MSVCDir%\BIN;%VSCommonDir%\TOOLS\%VcOsDir%;%VSCommonDir%\TOOLS;%PATH%
if "%OS%" == "" set PATH="%MSDevDir%\BIN";"%MSVCDir%\BIN";"%VSCommonDir%\TOOLS\%VcOsDir%";"%VSCommonDir%\TOOLS";"%windir%\SYSTEM";"%PATH%"
set INCLUDE=%MSVCDir%\ATL\INCLUDE;%MSVCDir%\INCLUDE;%MSVCDir%\MFC\INCLUDE;%INCLUDE%
set LIB=%MSVCDir%\LIB;%MSVCDir%\MFC\LIB;%LIB%
set VcOsDir=
set VSCommonDir=

  1. Next create a shortcut on your desktop to COMMAND.COM. Name the shortcut Go MIDL.
  2. Right mouse click over the shortcut and select to view the shortcuts properties. Select the Program tab and set the properties as follows: Cmd line: C:\WINDOWS\COMMAND.COM Working: "C:\Program Files\Microsoft Visual Studio\VC98" Batch file: BIN\VCVARS32.BAT
  3. Now select the Memory tab and make sure the Initial environment: property is set to at least 2048.

When you click on this shortcut, you will be in a DOS shell that is properly set for compiling IDL files. The shortcut will run the VCVARS32.BAT file for you. This properly initializes the DOS environment variables for the MIDL compiler.

  1. Next, copy the following IDL code, paste it into Notepad, and save the file as EX2.IDL:
// TypeLib : EX2.IDL (EX2)
// TargetFile : EX2.TLB
//
// Version 1.0
// - Author : Philip G. Fucich
// - Completed: 01/01/2000
// - Notes : Example 2 type library.
// UUID Usage:
// {C4408B80-EFC0-11D3-A88C-81F2B32E4671} : library EX2
// {C4408B82-EFC0-11D3-A88C-81F2B32E4671} : typedef exSampleEnum
// {C4408B84-EFC0-11D3-A88C-81F2B32E4671} : interface Box
[
uuid(C4408B80-EFC0-11D3-A88C-81F2B32E4671),
version(1.0),
helpstring("Example 2 Library")
]
library EX2
{
importlib("STDOLE2.TLB");
typedef
[
uuid(C4408B82-EFC0-11D3-A88C-81F2B32E4671),
helpstring("Sample enum declaration."),
v1_enum,
version(1.0)
]
enum exSampleEnum {
[helpstring("Helpstring for exDefault.")]
exDefault = 0,
exOne = 1,
exTwo = 2,
} exSampleEnum ;
[
uuid(C4408B84-EFC0-11D3-A88C-81F2B32E4671),
helpstring("A Box."),
nonextensible,
oleautomation,
]
interface Box : IUnknown {
[helpstring("Box height.")]
[propget] HRESULT Height ([out, retval] long* PropData );
[helpstring("Box width.")]
[propget] HRESULT Width ([out, retval] long* PropData );
[helpstring("Box depth.")]
[propget] HRESULT Depth ([out, retval] long* PropData );
};
}
  1. Copy or move EX2.IDL to the following directory:
C:\Program Files\Microsoft Visual Studio\VC98\
  1. Now click on your Go MIDL shortcut.
  2. In the DOS Window, type the following command:
bin\midl EX2.IDL

If all has gone well up to this point, you will have an EX2.TLB file. This file cannot be referenced in a VB project until it has been registered with Windows. The next steps will cover how to register your type library using some simple VB code.

  1. Move the EX2.IDL and EX2.TLB files to a directory of your choice. For this example, Ill say its in C:\Example2\.
  2. Open VB and create a new Standard EXE project.
  3. Go the project references dialog and add a reference to TypeLib Information as shown here:

  1. Click OK to return the to Form1 and add a command button to the form.
  2. Double click on the command button and add the following code to the Command1_Click() event procedure:
Dim o_TypeLib As TypeLibInfo
Set o_TypeLib = TLIApplication.TypeLibInfoFromFile("C:\Example2\EX2.TLB")
o_TypeLib.Register
MsgBox "The TypeLibrary is registered."
  1. Now, run the project and click the Command1 button.

The EX2.TLB will now be registered with Windows and thereby ready to reference in a VB project. To check out the EX2.TLB, open a new Standard EXE project, go to the project references dialog, and add it as a reference. You will find it listed as Example 2 Library. When youve added the reference, open the VB Object Browser and select EX2 in the Project/Library combo box. Your Object Browser will look something like this:

注:可以使用regtlib.exe来对tlb文件进行注册。

在遇到.net中有枚举类型,同时COM是原有系统不能更改代码时,因为regasm或者tlbexp生成的tlb文件会修改枚举的名称,可以将tlb转换成idl文件,通过修改名称之后将idl编译成tlb,然后再使用regtlib来注册使用。