Using Run-Time Dynamic Linking(使用运行时动态链接库)
// A simple program that uses LoadLibrary and // GetProcAddress to access myPuts from Myputs.dll.
#include <windows.h>
#include <stdio.h> typedef int (__cdecl *MYPROC)(LPWSTR); int main( void )
{
HINSTANCE hinstLib;
MYPROC ProcAdd;
BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; // Get a handle to the DLL module. hinstLib = LoadLibrary(TEXT("MyPuts.dll")); // If the handle is valid, try to get the function address. if (hinstLib != NULL)
{
ProcAdd = (MYPROC) GetProcAddress(hinstLib, "myPuts"); // If the function address is valid, call the function. if (NULL != ProcAdd)
{
fRunTimeLinkSuccess = TRUE;
(ProcAdd) (L"Message sent to the DLL function\n");
}
// Free the DLL module. fFreeResult = FreeLibrary(hinstLib);
} // If unable to call the DLL function, use an alternative.
if (! fRunTimeLinkSuccess)
printf("Message printed from executable\n"); return ; }
int 表示函数的返回值为 int 若是 TLSConnectToLsServer 函数,则应为 TLS_HANDLE
使用LoadLibrary把dll文件load进内存,使用GetProcAddress得到函数地址就可以使用了
#include <stdio.h>
#include <windows.h>
#include <string>
#include <iostream> using namespace std;
void main(void)
{
typedef int (__stdcall *PFUNCTION)( int k,int i);
//声明参数类型,以后会用到PFUNCTION
HMODULE hLib = ::LoadLibrary("xx.dll");
if ( NULL == hLib )
{
perror("装载DLL文件错误:");
}
else
{ PFUNCTION myAddFunction=myAddFunction=(PFUNCTION)::GetProcAddress(hLib,"ConnectEx");//ConnectEx是动态库中的方法
if ( NULL == myAddFunction)
{
perror("装载的DLL文件中无对应的函数:");
}
else
{
int k=myAddFunction(,);
cout <<k <<endl;
}
::FreeLibrary(hLib);
}
}
Using Run-Time Dynamic Linking(使用运行时动态链接库)的更多相关文章
- 使用dynamic引发的异常:无法对 null 引用执行运行时绑定
今天上午运营反映有商户的账单没有生成. 查看日志,在批量生成账单服务执行过程中,因为如下异常而中断了: 跑批异常 Microsoft.CSharp.RuntimeBinder.RuntimeBinde ...
- brew 安装的.net 运行时提示"Did you mean to run dotnet SDK commands?"
原因未知,但有解决方案 使用 brew cask 安装的.NET Core brew cask install dotnet 结果运行时出现: 解决方案: 下载官方 .pkg 文件安装,顺便卸载掉 b ...
- JVM 内存区域 (运行时数据区域)
JVM 内存区域 (运行时数据区域) 链接:https://www.jianshu.com/p/ec479baf4d06 运行时数据区域 Java 虚拟机在执行 Java 程序的过程中会把它所管理的内 ...
- JVM详解(三)——运行时数据区
一.概述 1.介绍 类比一下:红框就好比内存的运行时数据区,在各自不同的位置放了不同的东西.而厨师就好比执行引擎. 内存是非常重要的系统资源,是硬盘和CPU的中间仓库及桥梁,承载着操作系统和应用程序的 ...
- 深入浅出OOP(三): 多态和继承(动态绑定/运行时多态)
在前面的文章中,我们介绍了编译期多态.params关键字.实例化.base关键字等.本节我们来关注另外一种多态:运行时多态, 运行时多态也叫迟绑定. 运行时多态或迟绑定.动态绑定 在C#语音中,运行时 ...
- 趣谈iOS运行时的方法调用原理
一个成熟的计算机语言必然有丰富的体系,复杂的容错机制,处理逻辑以及判断逻辑.但这些复杂的逻辑都是围绕一个主线丰富和展开的,所以在学习计算机语言的时候,先掌握核心,然后了解其原理,明白程序语言设计的实质 ...
- Java AOP (2) runtime weaving 【Java 切面编程 (2) 运行时织入】
接上一篇 Java AOP (1) compile time weaving [Java 切面编程 (1) 编译期织入] Dynamic proxy 动态代理 Befor talking abou ...
- Java虚拟机运行时栈帧结构--《深入理解Java虚拟机》学习笔记及个人理解(二)
Java虚拟机运行时栈帧结构(周志明书上P237页) 栈帧是什么? 栈帧是一种数据结构,用于虚拟机进行方法的调用和执行. 栈帧是虚拟机栈的栈元素,也就是入栈和出栈的一个单元. 2018.1.2更新(在 ...
- jvm理论-运行时数据区
三大流行jvm sun HotSpot ibm j9 BEA JRockit Oracle 会基于HotSpot整合 JRockit. jvm运行时数据区 java虚拟机所管理的内存将会包括以下几个运 ...
随机推荐
- org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text
代码缺少这一行:job.setInputFormatClass(KeyValueTextInputFormat.class);
- JDK1.5新特性(三)……Varargs
援引 Varargs - This facility eliminates the need for manually boxing up argument lists into an array w ...
- 【原创】Mac上编译Hadoop1.0.3出现的一些问题
create-native-configure: [exec] configure.ac:47: error: possibly undefined macro: AC_PROG_LIBTOOL [e ...
- HW4.38
import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...
- 小波变换和motion信号处理(一)(转)
写的太好,不得不转:http://www.kunli.info/2011/02/15/fourier-wavelet-motion-signal-1/ 这是<小波变换和motion信号处理> ...
- CodeForces Round #179 (295A) - Greg and Array
题目链接:http://codeforces.com/problemset/problem/295/A 我的做法,两次线段树 #include <cstdio> #include < ...
- 阿里云服务器(CentOS)安装tomcat,jdk,布署J2EE项目
1.使用Xshell登录服务器,当然你也可以使用其他软件登录服务器 2.Linux服务器挂载数据盘,具体参见视频教程(quote:"一般来说服务器的数据盘需要和系统盘分开,当系统出现故障后能 ...
- [置顶] 自己写sqlhelper类
自己写sqlhelper类 using System; using System.Collections.Generic; using System.Configuration; using Syst ...
- [二]JFreeChart实践一
生成一张简单的图片 java代码: package com.lxl.chart; import javax.servlet.http.HttpSession; import org.jfree.cha ...
- J2EE 全面简介
原文地址:http://www.ibm.com/developerworks/cn/java/j2ee/ J2EE的概念 目前,Java 2平台有3个版本,它们是适用于小型设备和智能卡的Java 2平 ...