rdu-cpp

杨柳不折
随笔 - 13, 文章 - 0, 评论 - 4, 引用 - 0
数据加载中……

LoadLibrary 例子

 

// CliConsole.cpp : main project file.
#define _AFXDLL
#include 
<afx.h>
#include 
<tchar.h>
#include 
<iostream>
using namespace System;

bool PrintWndText(IntPtr hwnd, IntPtr lParam){
 String 
^wndText = Helper::GetWndText(hwnd);
 
if(wndText){
  Console::WriteLine(wndText);
 }

 
return true;
}


delegate int PrintDelegate(String^, String^);
int main(array<System::String ^> ^args)
{
 CallbackDelegate 
^callback = gcnew CallbackDelegate(PrintWndText);
 WindowsEnumerator 
^we = gcnew WindowsEnumerator(callback);
 we
->DoWork();

 HMODULE hLib 
= LoadLibrary(L"msvcrt.dll");
 
if(hLib){
  typedef 
int (*FUNCPTR)(const char*);
  FARPROC proc 
= GetProcAddress(hLib,"printf");
  FUNCPTR pFunc 
= reinterpret_cast<FUNCPTR>(proc);
  
if(pFunc){
   
using System::Runtime::InteropServices::Marshal;
   Delegate
^ ptr = Marshal::GetDelegateForFunctionPointer((IntPtr)pFunc,PrintDelegate::typeid);
   PrintDelegate
^ printDelegate = (PrintDelegate^)ptr;
   printDelegate(
"%s\r\n",L"good man");
  }

 }


 Console::WriteLine(L
"Hello World");
 system(
"pause");
 
return 0;
}


posted on 2009-04-10 11:18 rdu 阅读(5440) 评论(0)  编辑 收藏 引用 所属分类: Tips


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理