不注册Activex 直接调用它
此处的Activex是ATL方式的。
[ComVisible(false)]
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000001-0000-0000-C000-000000000046")]
internal interface IClassFactory
{
void CreateInstance([MarshalAs(UnmanagedType.Interface)] object pUnkOuter, ref Guid refiid, [MarshalAs(UnmanagedType.Interface)] out object ppunk);
void LockServer(bool fLock);
}
public delegate void IETestKey(IntPtr values);
internal static class ComHelper
{
//DllGetClassObject fuction pointer signature
private delegate int DllGetClassObject(ref Guid ClassId, ref Guid InterfaceId, [Out, MarshalAs(UnmanagedType.Interface)] out object ppunk);
//Some win32 methods to load\unload dlls and get a function pointer
private class Win32NativeMethods
{
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
public static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
[DllImport("kernel32.dll")]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll")]
public static extern IntPtr LoadLibrary(string lpFileName);
}
/// <summary>
/// Holds a list of dll handles and unloads the dlls
/// in the destructor
/// </summary>
private class DllList
{
private List<IntPtr> _dllList = new List<IntPtr>();
public void AddDllHandle(IntPtr dllHandle)
{
lock (_dllList)
{
_dllList.Add(dllHandle);
}
}
~DllList()
{
foreach (IntPtr dllHandle in _dllList)
{
try
{
Win32NativeMethods.FreeLibrary(dllHandle);
}
catch { };
}
}
}
static DllList _dllList = new DllList();
/// <summary>
/// Gets a class factory for a specific COM Class ID.
/// </summary>
/// <param name="dllName">The dll where the COM class is implemented</param>
/// <param name="filterPersistClass">The requested Class ID</param>
/// <returns>IClassFactory instance used to create instances of that class</returns>
internal static IClassFactory GetClassFactory(string dllName, string filterPersistClass)
{
//Load the class factory from the dll
IClassFactory classFactory = GetClassFactoryFromDll(dllName, filterPersistClass);
return classFactory;
}
private static IClassFactory GetClassFactoryFromDll(string dllName, string filterPersistClass)
{
//Load the dll
IntPtr dllHandle = Win32NativeMethods.LoadLibrary(dllName);
if (dllHandle == IntPtr.Zero)
return null;
//Keep a reference to the dll until the process\AppDomain dies
_dllList.AddDllHandle(dllHandle);
//Get a pointer to the DllGetClassObject function
IntPtr dllGetClassObjectPtr = Win32NativeMethods.GetProcAddress(dllHandle, "DllGetClassObject");
if (dllGetClassObjectPtr == IntPtr.Zero)
return null;
//Convert the function pointer to a .net delegate
DllGetClassObject dllGetClassObject = (DllGetClassObject)Marshal.GetDelegateForFunctionPointer(dllGetClassObjectPtr, typeof(DllGetClassObject));
//Call the DllGetClassObject to retreive a class factory for out Filter class
Guid filterPersistGUID = new Guid(filterPersistClass);
//Guid IClassFactoryGUID = new Guid("FCF82F0F-F8A9-4527-A36E-CC87FAFAA270"); //IClassFactory class id
Guid IClassFactoryGUID = new Guid("00000001-0000-0000-C000-000000000046"); //IClassFactory class id
Object unk;
if (dllGetClassObject(ref filterPersistGUID, ref IClassFactoryGUID, out unk) != 0)
return null;
//Yippie! cast the returned object to IClassFactory
return (unk as IClassFactory);
}
public static Delegate TestDll(string dllName)
{
IntPtr dllHandle = Win32NativeMethods.LoadLibrary(dllName);
if (dllHandle == IntPtr.Zero)
return null;
//Keep a reference to the dll until the process\AppDomain dies
//_dllList.AddDllHandle(dllHandle);
//Get a pointer to the DllGetClassObject function
IntPtr dllGetClassObjectPtr = Win32NativeMethods.GetProcAddress(dllHandle, "DllGetClassObject");
if (dllGetClassObjectPtr == IntPtr.Zero)
return null;
return (Delegate)Marshal.GetDelegateForFunctionPointer(dllGetClassObjectPtr, typeof(IETestKey));
}
}
不说废话,上代码
public enum IFilterReturnCode : uint
{
/// <summary>
/// Success
/// </summary>
S_OK = 0,
/// <summary>
/// The function was denied access to the filter file.
/// </summary>
E_ACCESSDENIED = 0x80070005,
/// <summary>
/// The function encountered an invalid handle,
/// probably due to a low-memory situation.
/// </summary>
E_HANDLE = 0x80070006,
/// <summary>
/// The function received an invalid parameter.
/// </summary>
E_INVALIDARG = 0x80070057,
/// <summary>
/// Out of memory
/// </summary>
E_OUTOFMEMORY = 0x8007000E,
/// <summary>
/// Not implemented
/// </summary>
E_NOTIMPL = 0x80004001,
/// <summary>
/// Unknown error
/// </summary>
E_FAIL = 0x80000008,
/// <summary>
/// File not filtered due to password protection
/// </summary>
FILTER_E_PASSWORD = 0x8004170B,
/// <summary>
/// The document format is not recognised by the filter
/// </summary>
FILTER_E_UNKNOWNFORMAT = 0x8004170C,
/// <summary>
/// No text in current chunk
/// </summary>
FILTER_E_NO_TEXT = 0x80041705,
/// <summary>
/// No more chunks of text available in object
/// </summary>
FILTER_E_END_OF_CHUNKS = 0x80041700,
/// <summary>
/// No more text available in chunk
/// </summary>
FILTER_E_NO_MORE_TEXT = 0x80041701,
/// <summary>
/// No more property values available in chunk
/// </summary>
FILTER_E_NO_MORE_VALUES = 0x80041702,
/// <summary>
/// Unable to access object
/// </summary>
FILTER_E_ACCESS = 0x80041703,
/// <summary>
/// Moniker doesn't cover entire region
/// </summary>
FILTER_W_MONIKER_CLIPPED = 0x00041704,
/// <summary>
/// Unable to bind IFilter for embedded object
/// </summary>
FILTER_E_EMBEDDING_UNAVAILABLE = 0x80041707,
/// <summary>
/// Unable to bind IFilter for linked object
/// </summary>
FILTER_E_LINK_UNAVAILABLE = 0x80041708,
/// <summary>
/// This is the last text in the current chunk
/// </summary>
FILTER_S_LAST_TEXT = 0x00041709,
/// <summary>
/// This is the last value in the current chunk
/// </summary>
FILTER_S_LAST_VALUES = 0x0004170A
}
[ComImport, Guid("接口的GUID")]
[InterfaceType(ComInterfaceType.InterfaceIsDual)]
public interface ISISSKeyManager
{
[DispId(1)]
IFilterReturnCode IETestKey([Out, MarshalAs(UnmanagedType.BStr)] out string KeyInfo);
[DispId(2)]
IFilterReturnCode CheckKeys([In, MarshalAs(UnmanagedType.BStr)]string KeyInfo, [In, MarshalAs(UnmanagedType.BStr)]string KeyInfo2, [Out, MarshalAs(UnmanagedType.BStr)]out string KeyTest);
}
public class LoadDllHelper
{
public static ISISSKeyManager LoadFilterFromDll(string dllName, string filterPersistClass)
{
//Get a classFactory for our classID
IClassFactory classFactory = ComHelper.GetClassFactory(dllName, filterPersistClass);
if (classFactory == null)
return null;
//And create an IFilter instance using that class factory
Guid IFilterGUID = new Guid("接口的GUID");
Object obj;
classFactory.CreateInstance(null, ref IFilterGUID, out obj);
return (obj as ISISSKeyManager);
}
}
调用方式:
var gethelperId = LoadDllHelper.LoadFilterFromDll("xxxx.dll", "com的GUID");
if (gethelperId != null)
{
string str = "1".PadLeft(300, '1');
IntPtr outPtr = Marshal.StringToBSTR(str);
var s = gethelperId.IETestKey(out str);
MessageBox.Show(s.ToString());
}
不注册Activex 直接调用它的更多相关文章
- Regsvr32注册ActiveX控件
命令:Regsvr32 XX.dll 注册ActiveX控件 Regsvr32命令参数:/u 卸载ActiveX控件/s 注册成功后不显示操作成功信息框/c 控制台输出/I 调用DllInstall安 ...
- 【VS开发】windows注册ActiveX控件
ActiveX控件是一个动态链接库,是作为基于COM服务器进行操作的,并且可以嵌入在包容器宿主应用程序中,ActiveX控件的前身就是OLE控件.由于ActiveX控件与开发平台无关,因此,在一种编程 ...
- Spring Cloud 服务端注册与客户端调用
Spring Cloud 服务端注册与客户端调用 上一篇中,我们已经把Spring Cloud的服务注册中心Eureka搭建起来了,这一章,我们讲解如何将服务注册到Eureka,以及客户端如何调用服务 ...
- SpringCloud实战之初级入门(二)— 服务注册与服务调用
目录 1.环境介绍 2.服务提供 2.1 创建工程 2.2 修改配置文件 2.3 修改启动文件 2.5 亲测注意事项 3.服务调用 3.1 创建工程 3.2 修改配置文件 3.3 修改启动文件 3.4 ...
- B/S(WEB)系统中使用Activex插件调用扫描仪实现连续扫描并上传图像(IE文件扫描并自动上传)
IE浏览器下使用Activex插件调用客户端扫描仪扫描文件并山传,可以将纸质档案(如合同.文件.资料等)扫描并将扫描图像保存到服务器,可以用于合同管理.档案管理等. 通过插件方式调用扫描仪扫描并获取图 ...
- 用C#编写ActiveX控件,开发浏览器控件,注册ActiveX 控件
用C#编写ActiveX控件,开发浏览器控件,注册ActiveX 控件用C#编写ActiveX控件 开发浏览器控件这是本控件开发完成后的一个简单应用.我们可以利用它以本地文件夹为单位来批量更新服务器的 ...
- 分布式应用开发 | SpringBoot+dubbo+zookeeper实现服务注册发现 | 远程服务调用
前言 通过新建两个独立服务--提供者.消费者,模拟两个独立分布的应用,通过使用dubbo+zookeeper来实现远程服务调用. 目录 项目搭建 provider-server consumer-se ...
- 关于使用regsvr32命令注册ActiveX控件失败的解决办法
昨天小编也遇到这样问题,步骤一切都对,没有错误,但是每次在命令行下输入的时候,都会弹出一个对话框: 最后我发现是存放ActiveX控件的路径中带有中文文件名字所导致,所以导致的错误,我们将所在路径下的 ...
- Spring Boot + Dubbo 可运行的例子源码-实现服务注册和远程调用
最近公司的一个分布式系统想要尝试迁移到Dubbo,项目本身是Spring Boot的,经过一些努力,最终也算是搭建起一个基础的框架了,放到这里记录一下.需要依赖一个外部的zookeeper. 源码地址 ...
随机推荐
- 二叉树的层序遍历 BFS
二叉树的层序遍历,或者说是宽度优先便利,是经常考察的内容. 问题一:层序遍历二叉树并输出,直接输出结果即可,输出格式为一行. #include <iostream> #include &l ...
- Java Web 学习链接
解决JSP中文乱码问题:http://www.cnblogs.com/chengkai/articles/2171848.html 编程思想之多线程与多进程:http://blog.csdn.net/ ...
- ThinkPHP 利用.htaccess文件的 Rewrite 规则隐藏URL中的 index.php
1.首先修改Apache的httpd.conf文件. 确认httpd.conf配置文件中加载了mod_rewrite.so 模块,加载的方法是去掉mod_rewrite.so前面的注释#号 讲http ...
- Mac Pro 资源管理器 Double Commander“个性化设置” 备份
操作系统自带的资源管理器,总是有些别扭的地方,在 Windows 系统下,我一般用 Total Commander(破解版)来作为替代品.现在换为 Mac 系统,自带的 Finer 也不怎么好用,连最 ...
- Shell入门教程:流程控制(1)命令的结束状态
在Bash Shell中,流程控制命令有2大类:“条件”.“循环”.属于“条件”的有:if.case:属于“循环”的有:for.while.until:命令 select 既属于“条件”,也属于“循环 ...
- python 环境配置
每个项目都应该有自己的虚拟环境,如何方便的操作呢? 1. 安装 virtualenv 2. 安装 virtualenvwrapper 3. 创建目录用来存放虚拟环境 mkdir $HOME/.virt ...
- 项目vue2.0仿外卖APP(一)
最近用vue.js做一个仿饿了么外卖APP的项目,现在也把流程啊什么的暂时先整理一下在这个博客上面. 当然,这个过程会有点长,不过确实能学到很多东西. 话不多说,马上开始吧. 1.项目介绍 选用当前最 ...
- 浅谈JS之AJAX
0x00:什么是Ajax? Ajax是Asynchronous Javascript And Xml 的缩写(异步javascript及xml),Ajax是使用javascript在浏览器后台操作HT ...
- BZOJ 4723: [POI2017]Flappy Bird
Description 从一个点到一条直线,每次纵坐标只能增加或减少1,有些位置有障碍,求最少增加步数. Sol 贪心. 或许是贪心吧...反正在可到达的范围内,纵坐标尽量小... 做的时候维护一下两 ...
- matplotlib绘制多组 散点连线图【用于对比】待实现
绘制散点+连线图: http://www.cnblogs.com/aaronhoo/p/5150596.html http://zhidao.baidu.com/link?url=Q1b7NG8eEz ...