【发布时间】:2016-02-23 10:25:23
【问题描述】:
我正在尝试在我的 c# 程序中使用 ExtraPutty 的功能。 ExtraPutty 为此提供了一个 dll 甚至是 c# 中的示例程序。
该示例不适用于我。当示例程序调用其中一个 extraputty 函数时,我收到以下错误消息:“程序无法启动,因为缺少 lua53.dll。重新安装程序以解决此问题。”
我将 dll 放入输出文件夹并 我尝试安装 dll,但 Windows 无法将其识别为有效的 dll。 我用过
regsrv32 /ic:\path\lua53.dll
并收到此错误消息:“Modul 已加载,但未找到 dllRegisterServer-EntryPoint。确保它是有效的 dll 或 ocx 文件并重复。”
dll 有什么问题?如何正确安装?
然后我制作了自己的程序: 我没有得到 dll 错误,但我还没有得到功能。 我想我在导入和数据类型方面做错了。 我正在发送命令“Unanme -r”,它应该返回目标操作系统的一些版本号。但是什么都没有返回。
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ExtraPuttyDLL_Test
{
class Program
{
[DllImport("C:\\Users\\xroeseners\\Desktop\\ExtraPuTTY-0-29\\ExtraPuTTY.dll", EntryPoint = "Connexion")]
static extern int OpenConnection( string TargetName,
ref UInt32 ConnectionId,
string Login,
string Password,
byte ShowTerminal,
Int32 Protocol,
UInt32 PortNumber,
Int32 Report,
CallbackRcvData Callback,
UInt32 SpecSettings);
[DllImport("C:\\Users\\xroeseners\\Desktop\\ExtraPuTTY-0-29\\ExtraPuTTY.dll", EntryPoint = "SendRcvData")]
static extern int SendData( UInt32 ConnectionId,
string Data,
string Title,
string Comments,
Int32 TimeCapture,
char[] Buf,
Int32 MaxSizeData,
UInt32 settings);
// int SendRcvData(unsigned long ConnectionId,char *Command,char *Title,char *Comments,long TimeCapture,char **DataRcv,long MaxSizeofData,unsigned long settings);
// Settings Bit fields of settings (2^0 : CRLF (0 send,1 not send),2^1 : Virtual key codes (0 no virtual key codes in command,1 yes)...reserved)
// See FAQ page for a description of all virtual keys codes.
[DllImport("C:\\Users\\xroeseners\\Desktop\\ExtraPuTTY-0-29\\ExtraPuTTY.dll", EntryPoint = "CloseConnexion")]
static extern int CloseSession(UInt32 ConnectionId);
public static UInt32 myConnectionId;
public delegate int CallbackRcvData(UInt32 ConnectionId, IntPtr Data, Int32 size, Int32 Status);
public static string myString;
static void Main(string[] args)
{
myConnectionId = new UInt32();
int size, status;
char[] data = null;
CallbackRcvData Callback = new CallbackRcvData(RcvData);
//CallbackRcvData = new CallbackRcvData(myConnectionId,
OpenConnection("192.168.8.98",
ref myConnectionId,
"admin", // user
"admin", // password
0, // no display of putty terminal
1, // SSH Protocol
22, // Port
0, // Generate Report: 0 = nein
Callback,
0); // bin_000 -> dont wait login prompt, dynamically starting putty log, ssh v1 otherwise ssh v2
SendData(myConnectionId,
"uname -r",
"",
"",
5000,
data,
20000,
0);
CloseSession(myConnectionId);
}
public static int RcvData(UInt32 ConnectionId, IntPtr Data, Int32 size, Int32 Status)
{
if ((size > 0) && (Status == 0) && (Data != null))
{
myString = Marshal.PtrToStringAnsi(Data) ;
}
return 0;
}
}
}
【问题讨论】:
-
我忘了添加 SendData 等声明 int SendRcvData(unsigned long ConnectionId,char *Command,char *Title,char *Comments,long TimeCapture,char **DataRcv,long MaxSizeofData,unsigned long设置); int Connexion(char *TargetName,unsigned long *ConnectionId,char *Login,char *Password,bool ShowPuTTY,long Protocol,unsigned long PortNumber,long GenerateReport,int *CallBackRcvData,unsigned long SpecSettings);