码迷,mamicode.com
首页 > 编程语言 > 详细

关于各种编程语言调用C星寻路插件的例子

时间:2015-06-09 06:09:20      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

DLL的调用

1、VB

Public Declare Function FindPath Lib "zd/LY_Cstar_VB.dll" (ByVal StarX As Integer, ByVal StarY As Integer, ByVal StopX As Integer, ByVal StopY As Integer, ByVal Space As Integer, ByVal MapSRC As String, ByVal ClickXY As Integer, ByVal sn As String) As String

Private Sub Command1_Click()
Dim ss As String
ss = FindPath(154, 39, 35, 210, 0, "zd/1.bmp", 2, "dl_8889888")
If ss <> "-1" Then
MsgBox (ss)
End If
End Sub

注意VB不能像DELPHI一样传递变量 赋值变量返回 所以特别做了有返回值的函数FindPath,另外传递字符串 请用PCHAR类型

2、易语言

.版本 2

.DLL命令 FindPath, 逻辑型, "LY_Cstar.dll", "FindPath"
.参数 StarX, 整数型
.参数 StarY, 整数型
.参数 StopX, 整数型
.参数 StopY, 整数型
.参数 Space, 整数型
.参数 MapSRC, 文本型
.参数 ClickXY, 整数型
.参数 sn, 文本型
.参数 outstring, 整数型, 传址

.局部变量 DD, 整数型
.局部变量 SS, 逻辑型

SS = FindPath (418, 117, 170, 261, 0, “2.bmp”, 2, “dl_8889888”, DD)
.如果 (SS)
信息框 (“计算值:” + 指针到文本 (DD), 0, )
.否则
信息框 (“设置参数不能到达此处:”, 0, )

COM DLL方式

3、TC

//开始按钮_点击操作
功能 开始_点击()
TS = com("DL.CStar") // 创建插件对象 com关键字必须是小写
ss= TS.FindPath(111,41,23,85,0,"C:\\Users\\momo\\Desktop\\C星寻路验证程序\\pic\\1004.bmp",2,"保密安全码")
辅助.消息框(ss)
功能结束

4、按键精灵

ss=Plugin.DL_Cstar.FindPath(154,39,35,210,0,"Map\1.bmp",2,"dl_8889888")
MessageBox ss

5、Delphi

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;

implementation

{$R *.dfm}
//------------------------------------------------------------------------------自动释放资源
function FindPath(StarX, StarY, StopX, StopY, Space: Integer; MapSRC: PAnsiChar;ClickXY: Integer; sn: PAnsiChar;var outstring: PAnsiChar): Boolean;stdcall;External ‘zd/LY_Cstar.dll‘ ;//NAME ‘FindPath2‘
//------------------------------------------------------------------------------//
procedure TForm2.Button1Click(Sender: TObject);
var
ss:PAnsiChar;
begin
if FindPath(154,39,35,210,0,‘zd/1.bmp‘,2,‘dl_8889888‘,ss) then
ShowMessage(ss);
end;

end.

7、VC

// fffDlg.cpp : implementation file
//

#include "stdafx.h"
#include "fff.h"
#include "fffDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CFffDlg dialog

CFffDlg::CFffDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFffDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFffDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CFffDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFffDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CFffDlg, CDialog)
//{{AFX_MSG_MAP(CFffDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFffDlg message handlers

BOOL CFffDlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application‘s main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here

return TRUE; // return TRUE unless you set the focus to a control
}

// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.

void CFffDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting

SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;

// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}

// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFffDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}

void CFffDlg::OnOK()
{
// TODO: Add extra validation here
String d;
String d1,d2;
d1="C:\\LY_Cstar.dll";
d2="C:\\1.bmp";

HINSTANCE Hint = ::LoadLibrary(d1);//加载我们刚才生成的dll
if(Hint)
{
typedef void(WINAPI*ADD)(CString);//函数指针类型
ADD b = NULL;
b = (ADD)GetProcAddress(Hint,"A");//取得dll导出的add方法
typedef CString (WINAPI*ADD1)(int,int,int,int,LPCTSTR);//函数指针类型
ADD1 B=NULL;
B = (ADD1)GetProcAddress(Hint,"GetPath");//取得dll导出的add方法
b(d2);
//d=B(2,2,20,20,"19921005");
}
CDialog::OnOK();
}

关于各种编程语言调用C星寻路插件的例子

标签:

原文地址:http://www.cnblogs.com/plug/p/4562385.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!