添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

delphi 导出请加stdcall

---------------------- Delphi --------------------------

library DepDll;
{ Important note about DLL memory management: ShareMem must be the
  first unit in your library's USES clause AND your project's (select
  Project-View Source) USES clause if your DLL exports any procedures or
  functions that pass strings as parameters or function results. This
  applies to all strings passed to and from your DLL--even those that
  are nested in records and classes. ShareMem is the interface unit to
  the BORLNDMM.DLL shared memory manager, which must be deployed along
  with your DLL. To avoid using BORLNDMM.DLL, pass string information
  using PChar or ShortString parameters. }
  SysUtils,
  Classes;
//加法测试
Function TestAdd(p1, p2 : Integer):Integer;stdcall;
begin
  Result:=p1+p2;
//字符串输入与输出测试
Function ShowString(s1, s2:PChar; pOut:PChar):Integer;stdcall;
strRes:String;
begin
  strRes:='this is from delphi s1:'+ StrPas(s1) + ' s2:' + StrPas(s2);
  Move(strRes[1], pOut^, Length(strRes));
{$R *.res}
//函数导出
exports
  TestAdd,ShowString;
begin

---------------------- C++ ----------------------

CString strPath = _T("D:\\Program Files (x86)\\Borland\\Delphi7\\Projects\\DepDll.dll");
	HINSTANCE hUKey = LoadLibrary(strPath);
	if (hUKey != NULL){
		//参数为整型的加法测试
			int nRes;
			typedef int(__stdcall *TADD)(int, int);
			TADD pAdd = (TADD)GetProcAddress(hUKey, "TestAdd");
			if (pAdd != 0){
				nRes = pAdd(100, 123);
		//参数为字符串的字符串测试
			int nRes;
			typedef int(__stdcall *SHOWSTR)(char*, char*, char*);
			SHOWSTR pShowStr = (SHOWSTR)GetProcAddress(hUKey, "ShowString");
			char* pBuf = new char[512];
			memset(pBuf, 0, 512);
			if (pShowStr != 0){
				nRes = pShowStr("2018 delphi", "param 2", pBuf);
			delete[] pBuf;
		FreeLibrary(hUKey);
                    说明:delphi 导出请加stdcall---------------------- Delphi --------------------------library DepDll;{ Important note about DLL memory management: ShareMem must be the  first unit in your library's USES cla...
int rtn = 0;
String dllName = "XXXX.dll";
HINSTANCE hInstance = LoadLibrary(dllName.c_str());
MyFunction * pMyFun...
				
小知识C++中以&的参数在Delphi必须以const或者var申明,否则会产生错误。WIN32PROJECT1_API void test8(RECT &a) { a.left = 1; a.top = 2; a.right = 3; a.bottom = 4; } 此时参数为 RECT &a,在Delphi中有两种申明方式,各有不同 方式一 var procedur
互联网上有大量有用的 C++ 库。我们也在这个博客上展示了C++ 的许多伟大用途。C++ 通常具有极高的性能。如果我们有 C++ 库的源代码,我们就可以创建一个包,然后我们就可以在 Delphi 程序中使用 C++。尽管 C++ 库的源代码通常不可用。在商业 C++ 库中,通常只获得几个 C++ 头文件和静态库文件 (.lib),而没有任何随附的 .cpp 源文件。因此,在这种情况下,当我们想在 Delphi 应用程序中使用那些 C++ 库时,我们可以使用代理 DLL 来实现。 如何创建一个代理...
[DllImport("Project2.dll", EntryPoint = "dadd", ExactSpelling = false, CallingConvention = CallingConvention.StdCall)] public static extern i...
C/C++调用delphi编写的dll文件1. delphi 编写的dll文件源码library xrBitOperation; { Important note about DLL memory management: ShareMem must be the first unit in your library's USES clause AND your project's (sele...
调用C指的是使用C语言编写的函数或库,并在程序中通过调用这些函数或库来实现相应的功能。C是一种高级编程语言,常用于系统级编程、嵌入式系统、游戏开发等领域。 在使用C语言编写的函数或库之前,需要在程序中进行相关的头文件包含及函数声明。头文件包含通常使用#include指令,函数声明包括函数名、参数列表及返回值类型等。 调用C语言函数或库的方式主要有两种,分别是静态链接和动态链接。静态链接是指将函数库的代码在编译时就链接到程序中,运行时不再需要函数库的支持;而动态链接是指在程序运行时才通过操作系统动态加载函数库的代码,可以减小程序的体积。 C语言作为一种高效、易用、可移植的编程语言,被广泛应用于各种领域。对于开发人员来说,熟练掌握C语言调用方式,可以大大提高开发效率。