EvoTalk

Posts Tagged ‘dll

20 一月, 2009

Perl Call VC Dll

Posted by: asd In: Code Snippet| Perl| 程式設計

VC DLL實作,calling convention 必需是__stdcall
view plain

CODE:

#include <windows.h>

#include <stdio.h>

 

int __stdcall GetIntFromVC(int x )

{

    x *= 2;

    return x;

}

 

int  __stdcall GetStrFromVC(char* pbstr, char *lpBuffer)

{

 return sprintf(lpBuffer, "*** %s ***", pbstr);

}

避免 name mangling ,加入 .def
view plain

CODE:

LIBRARY test

 

EXPORTS

GetIntFromVC  @1

GetStrFromVC  @2

Perl call dll
view plain

CODE:

#! perl -slw

use strict;

use Win32::API;

 

#傳入一個參數,回傳一個值 ,N: value is a number (long)

my $fun1 = new Win32::API('test.dll', 'GetIntFromVC', [...]

Tags: ,

29 六月, 2006

VB Pass String to VC Dll

Posted by: asd In: C++| Code Snippet| 程式設計

In VC DLL

function 前不需要加入 __declspec(dllexport),要匯出的function名稱加入 .def 即可,避免name mangling
function 之 calling convertion 為 __stdcall
ex. int __stdcall GetCPUSpeed()
使用.def 作出的 Dll,可被 VC 及 VB 程式呼叫

VB 傳參數進 VC DLL
例一 : Call By Reference
In VB,若function宣告為
Private Declare Function GetStrFromVC1 "z:DllDebugDll2.dll" ( ByRef PA as integer, ByRef str1 as String) As String
呼叫
view plain

Visual Basic:

Dim strRet as String

Dim PA as Integer

Dim strOutStr as [...]

Tags: , ,

之前用 VC 時,若 WorkSpace 包含 Dll 專案,會產出.lib及.dll,.lib通常會設定統一集中在lib目錄下,dll必須與執行檔同個目錄才能執行。所以說必須手動再把 dll 拷貝到主程式 Active Project的工作目錄下,若不只一個Dll專案那就累人了,必須手動逐一copy。其實只要在Dll專案 Setting->Post build step 新增 command 代表當此專案build完後要作什麼事情,可以下
XCopy ..liblibText2Phone.dll ..gengrm /Y /F /D
/Y /F /D是xcopy的參數,分別表示

/Y: 不要提示您確認是否要覆蓋一個已經存在的檔案
/F: 在複製時顯示來源及目的檔案的全部檔名
/D: 複製在指定日期當天或之後發生變更的檔案。如果沒有給日期, 只複製那些來源檔案日期比目的檔案日期為新的檔案。

Tags:

08 十二月, 2005

Calling C++ DLLs from VC++ and VB

Posted by: asd In: C++| Code Snippet| 程式設計

Calling a DLL C++ function from a VC++ application
Calling a DLL C++ class from a VC++ application
Calling a DLL C++ function from a VB application
Calling a DLL C++ class from a VB application
Loading a C++ DLL dynamically from a VC++ application

Tags:


  • BK: 大於和小於在今日更廣泛地使用於標籤上,故在此補充該英文用法: : angle bracket []: square bracket
  • luh1688: 非常實用且謝謝!~
  • asd: 好的,不過很久沒修改了,不知道能不能動 寄到您的yahoo信箱
  • LIANG: nice post, thank you
  • Justmaker: 您好,請問可以跟你要source嗎?我最近有在看股票,想要enhance您的小工具,不知是否可以開放?

Category