知识若不分享 实在没有意义 http://www.d-programming-language-china.org 20070709
点击下面网址查看原文:
http://www.d-programming-language-china.org
本文代码 yidabu 在DMD1.018上测试通过。
D programming language type library importer 下载
juno库对com进行了很好的封装。如果要用D语言进行com相关开发,目前来说juno库是不二选择。
首先到juno的主页下载juno
http://www.dsource.org/projects/juno
并按照D语言论坛 http://www.d-programming-language-china.org 文章介绍修改juno以通过新版DMD的编译。编译得到juno.lib
再下载type library importe(tlpimpd),放到系统环境变量设置的路径中去。
type library importer tlbimpd 实例1
尝试编译下面的例子:
http://www.dsource.org/projects/juno/wiki/TypeLibraryImporterTips( 本文出处: http://www.d-programming-language-china.org )
首先用下面命令生成导入库:
tlbimpd.exe scrrun.dll /comments
得到模块scripting.d
import std.stdio : writef, writefln;
import juno.com.core;
pragma(lib,"juno.lib");
import scripting;
/* scripting.d was generated by running a patched version of tlbimpd on
Microsoft Scripting Runtime (scrrun.dll) */
void main()
{
IFileSystem3 objFSO = FileSystemObject.coCreate!(IFileSystem3);
ITextStream objOutFile;
int hresult;
wchar* fileName = utf8ToBstr("test_scripting.txt");
hresult = objFSO.CreateTextFile(
fileName,
VARIANT_TRUE,
VARIANT_FALSE,
objOutFile);
freeBstr(fileName);
wchar* str = utf8ToBstr("testing 1, 2, 3...");
objOutFile.WriteLine(str);
objOutFile.Close();
freeBstr(str);
writefln("Test succeeded");
objOutFile.Release();
objFSO.Release();
}
type library importer tlbimpd 实例2
IE的例子
生成导入库:
tlbimpd.exe msscript.ocx /comments
创建IE的例子:
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&message_id=52648&attachment_id=1
import std.stdio : writef, writefln;
import juno.com.core;
import msscriptcontrol;
pragma(lib,"juno.lib");
void main()
{
IScriptControl objScript = ScriptControl.coCreate!(IScriptControl);
objScript.set_Language(utf8ToBstr("VBScript"));
wchar* lang;
objScript.get_Language(lang);
writefln(bstrToUtf8(lang));
objScript.ExecuteStatement(utf8ToBstr(`
MsgBox "Get ready for Internet Explorer!"
Dim ieApp
Set ieApp = CreateObject("InternetExplorer.Application")
ieApp.Navigate("http://www.d-programming-language.org/")
ieApp.Visible = True
MsgBox "Yay for Juno!"
ieApp.Visible = False
Set ieApp = Nothing
`));
}
type library importer tlbimpd 实例3
http://www.dsource.org/projects/juno/wiki/Tutorials/Automation
import juno.io.core, juno.com.core, shell32;
pragma(lib,"juno.lib");
void main() {
IShellDispatch shell = Shell.coCreate!(IShellDispatch);
releaseAfter (shell, {
// Get a reference to the Desktop folder.
Folder folder;
shell.NameSpace(toVariant(ShellSpecialFolderConstants.ssfDESKTOP), folder);
if (folder !is null) {
releaseAfter (folder, {
// Get the collection of FolderItem objects.
FolderItems items;
folder.Items(items);
if (items !is null) {
releaseAfter (items, {
// Iterate through all the FolderItem objects.
int count;
items.get_Count(count);
for (int i = 0; i < count; i++) {
FolderItem item;
items.Item(toVariant(i), item);
if (item !is null) {
releaseAfter (item, {
// Get the name of the item.
wchar* bstrName;
item.get_Name(bstrName);
// Convert the BSTR to a UTF-8 string. bstrToUtf8 frees the BSTR.
char[] name = bstrToUtf8(bstrName);
// Display the result.
Console.writeln(name);
});
}
}
});
}
});
}
});
}
( lastupdate:20070709 最新文章请访问http://www.d-programming-language-china.org )关于一大步成功社区:
yidabu提倡在交流中学习,在分享中提高
收集感兴趣的知识,写下心得,通过网络与别人一起分享
理解一点就实践一步,收获什么就分享什么,成功就是这样一点点一步步累积起来的
网络只是一个工具,只有自己身心提高才是实实在在的。d-programming-language-china.org为大家提供一个学习交流各种知识的平台