由VC生成DLL,以供VB等调用
2008-02-01 09:24
911 查看
一、在XXX.def中加入(假设工程名叫XXX,要输出的函数名叫MyDLLFunc())
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
EXPORTS
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
; Explicit exports can go here
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
MyDLLFunc
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
二、在XXX.cpp中写函数的定义
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// 输入一个字符串,处理后输出
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
extern "C" bool __stdcall EXPORT MyDLLFunc(LPTSTR inputStr, TCHAR** outputStr)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AFX_MANAGE_STATE(AfxGetStaticModuleState());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CString instr = inputStr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CString outstr = SomeProcess(instr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_tcscpy(*outputStr, (LPCTSTR)out);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
三、在VB中调用
Public Declare Function MyDLLFunc Lib "C:/yyy/xxx.dll" (ByVal inputStr As String, ByRef outputStr As String) As Boolean
Sub M1() ' 其实是个宏 -_-
Dim mystr As String * 4096
If MyDLLFunc("ABC", mystr) Then
MsgBox sss
End If
End Sub
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
EXPORTS
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
; Explicit exports can go here
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
MyDLLFunc
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
二、在XXX.cpp中写函数的定义
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
// 输入一个字符串,处理后输出
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
extern "C" bool __stdcall EXPORT MyDLLFunc(LPTSTR inputStr, TCHAR** outputStr)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
AFX_MANAGE_STATE(AfxGetStaticModuleState());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CString instr = inputStr;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
CString outstr = SomeProcess(instr);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
_tcscpy(*outputStr, (LPCTSTR)out);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return true;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
三、在VB中调用
Public Declare Function MyDLLFunc Lib "C:/yyy/xxx.dll" (ByVal inputStr As String, ByRef outputStr As String) As Boolean
Sub M1() ' 其实是个宏 -_-
Dim mystr As String * 4096
If MyDLLFunc("ABC", mystr) Then
MsgBox sss
End If
End Sub
相关文章推荐
- sqlserver 2000 触发器 存储过程调用外部dll,可以使vb,vc,delphi生成
- sqlserver 2000 触发器 存储过程调用外部dll,可以使vb,vc,delphi生成
- VB.NET动态加载C#或VB.NET生成的DLL文件调用动画教程[黑白智慧写](动态调用DLL).txt
- VB.NET 生成DLL文件 调用DLL文件
- 在 VB 中调用 VC 写的 DLL
- 关于使用vc++调用matlab生成的dll传递数组的问题
- vb.net 下调用生成dll的SqlHelper
- 分享如何在VB中调用VC编写的DLL
- VC++ (MFC)调用 C#生成DLL的方法
- Delphi 调用VC生成的DLL
- 再谈在VB中调用VC++开发的DLL
- vb调用vc编的dll文件
- Java採用JNI调用VC++生成的dll(Java与C++交互)
- VC调用Matlab生成的DLL
- Visual Studio 2008中用VB调用VC++的DLL文件
- 用VC开发API形式的DLL给VB调用的范例
- Java Call DLL(compiled by VB) java调用vb生成的dll
- 【混合编程】VC调用Matlab生成的DLL
- 在非VS环境下C++ Builder,Delphi,VC,VB等调用C#开发的DLL的完整方法
- 在vb和asp中调用c#生成的.net的dll,详细步骤、截图和代码