| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2348 人关注过本帖
标题:急!关于类调用类!!
只看楼主 加入收藏
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
 问题点数:0 回复次数:15 
急!关于类调用类!!

我建了一个项目luyin1
在此项目里添加了一个类D160A , 内容如下:

using System;
using System.Runtime.InteropServices;

namespace luyin1
{
/// <summary>


/// 说明:创建类D160,导出并封装D系列模拟卡函数
/// </summary>

public struct TC_INI_TYPE
{
public short wCardNo;
public short wCardType;
public short wConnect;
public short wIRQ;
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 32)]
public char[] cbDir;
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 32)]
public short[] wAddress;
public short wMajorVer;
public short wMinorVer;
[MarshalAs(UnmanagedType.ByValArray , SizeConst = 32)]
public short[] wChType;

}

public struct TC_INI_TYPE_MORE
{
}

class D160A
{
public const short MAX_CHANNEL_NO = 128;
public const short LEN_FILEPATH = 128;
public const short MAX_CARD_NO = 32;

//初始化函数;
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern long LoadDRV();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void FreeDRV();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern long EnableCard(short wusedCh, short wFileBufLen);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void DisableCard();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void GetSysInfo(ref TC_INI_TYPE TmpIni);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void GetSysInfoMore(ref TC_INI_TYPE_MORE TmpMore);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short CheckValidCh();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short CheckChType(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short CheckChTypeNew(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool IsSupportCallerID();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void SetPackrate(short wPackRate);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void PUSH_PLAY();
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void SetBusyPara(short BusyLen);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void SetDialPara(short RingBack, short RingBack0, short BusyLen, short RingTimes);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern long NewReadPass(short wCardNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void D_SetWorkMode(short wChnlNo, byte cbWorkMode, byte cbModeVal);

//振铃及摘挂机函数;
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool RingDetect(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void OffHook(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void HangUp(short wChnlNo);

//放音函数;
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StartPlay(short wChnlNo, byte[] PlayBuf, int dwStartPos, int dwPlayLen);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StopPlay(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool CheckPlayEnd(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool StartPlayFile(short wChnlNo, byte[] FileName, int StartPos);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StopPlayFile(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void RsetIndexPlayFile(short Line);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool AddIndexPlayFile(short Line, byte[] FileName);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool StartPlayIndex(short wChnlNo, short[] pIndexTable, short wIndexLen);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool CheckIndexPlayFile(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StopIndexPlayFile(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool StartIndexPlayFile(short wChnlNo);



//录音函数
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StartRecordFile(short wChnlNo,byte[] FileName, int dwPlayLen);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StartRecordFileNew(short wChnlNo,byte[] FileName, int dwPlayLen, int dwRecordStartPos);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void CheckRecordEnd(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StopRecordFile(short wChnlNo);

//收码、拔号、信号音检测函数
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void InitDtmfBuf(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short GetDtmfCode(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern bool DtmfHit(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void StartSigCheck(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void FeedSigFunc();

//收主叫号码有关的函数
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern void ResetCallerIDBuffer(short wChnlNo);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short GetCallerIDRawStr(short wChnlNo, byte[] IDRawStr);
[DllImport("Tc08a32.dll",CharSet=CharSet.Auto)]
public static extern short GetCallerIDStr(short wChnlNo, byte[] IDStr);

//新增信号音函数
[DllImport("NewSig.dll",CharSet=CharSet.Auto)]
public static extern void Sig_Init(int Times);

}
}

我现在又在项目里加了一个类Class2,在Class2中需要调用类D160中的放音函数应该怎么实现呢?

搜索更多相关主题的帖子: 项目 public 
2006-08-10 13:12
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 
luyin1.D160A.方法名

[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-10 13:44
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 

给你一个例子

[QUOTE]using System;
namespace *****.USB
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class ReadUSBMsg
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[System.Runtime.InteropServices.DllImport ("noshow.dll")]
private static extern int OpenCD();
[System.Runtime.InteropServices.DllImport ("noshow.dll")]
private static extern int CloseCD();
[System.Runtime.InteropServices.DllImport ("noshow.dll")]
private static extern uint GetSerial_0();
[System.Runtime.InteropServices.DllImport ("noshow.dll")]
private static extern uint GetSerial_1();
// public static void Main()
// {
// GetNumberString();
// }
public static string GetNumberString()
{

uint a,b;
OpenCD();
a=GetSerial_0();
b=GetSerial_1();
CloseCD();

string temp=Convert.ToString(b,16)+Convert.ToString(a,16);
return temp=temp.ToUpper();
}
}
}[/QUOTE]



此号自封于2006年11月30日
2006-08-10 13:52
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 
楼上的大虾,小弟实在太小白了,看了你的例子有些不明白的地方还望大虾们指点迷经的说

// public static void Main()
// {
// GetNumberString();
// }
楼上把这三句注释了那程序的入口在那里呢?


string temp=Convert.ToString(b,16)+Convert.ToString(a,16);
return temp=temp.ToUpper();
这两句是什么意思呢?

2006-08-10 16:29
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
以下是引用wuyangmouse在2006-8-10 16:29:16的发言:
楼上的大虾,小弟实在太小白了,看了你的例子有些不明白的地方还望大虾们指点迷经的说

// public static void Main()
// {
// GetNumberString();
// }
楼上把这三句注释了那程序的入口在那里呢?


string temp=Convert.ToString(b,16)+Convert.ToString(a,16);
return temp=temp.ToUpper();
这两句是什么意思呢?


这个例子是从USB里读出一段信息
即是 sn_0,sn_1然后赋予 a 和 b
前面调用了动态链接库之后声明其内的函数和接口类型
然后下面我写了一个方法就是GetNumberString
如果你想在这个类里调用的话就把注释去掉
在方法前加static 这样就可以执行了
在这里是打印控制台信息以检查读取的是否正确用的
检查后我把它注释掉了
因为实际运用的时候不用输出的
如果你不在这个类里用的话
就把Main注释掉然后在其他类中声明实例然后调用这个方法就行了

至于后面那2行
string temp=Convert.ToString(b,16)+Convert.ToString(a,16);
return temp=temp.ToUpper();
Convert是一个转换类 把后面的东西转换为一个串
因为a和b 读出来的时候是数字类型 16的意思是转换成16进制的串

总体功能就是从USB读取其序列号

[此贴子已经被作者于2006-8-10 16:38:06编辑过]


此号自封于2006年11月30日
2006-08-10 16:35
chenjin145
Rank: 1
等 级:禁止访问
帖 子:3922
专家分:0
注 册:2006-7-12
收藏
得分:0 

會又默認入口的
都是static方法 入口搞為private


應該把b和a轉為16進制的string吧

返回temp的大寫


[url=javascript:alert(1);] [div]fdgfdgfdg\" on\"[/div] [/url]
2006-08-10 16:36
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 
哦,终于了了!

谢谢两位大虾
2006-08-10 17:03
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 

我根据上面的类D160A又写了一个类CLass2 内容如下:

public class Class2
{
public enum CHANNEL_STATE : short
{
CH_FREE,
CH_RECEIVEID,
CH_WAITSECONDRING,
CH_WELCOME,
CH_CHOOSE,
CH_CHOOSE1,
CH_ACCOUNT,
CH_ACCOUNT1,
CH_PASSWORD,
CH_PASSWORD1,
CH_SELECT,
CH_SELECT1,
CH_OFFHOOK,
}

public enum CHANNEL_TYPE : short
{
User,
Trunk,
Empty
}

public struct LINESTRUCT
{
public CHANNEL_TYPE nType;
public CHANNEL_STATE State;
// [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)]
public string CallerID;
// [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)]
public string Dtmf;
public int nTimeElapse;
}

public static string www()
{

long LoadDriveFlag;
LoadDriveFlag = D160A.LoadDRV();
if(LoadDriveFlag == 1)
{
MessageBox.Show("Load drive failure");

}
short TotalLine;
TotalLine = D160A.CheckValidCh();
if(D160A.EnableCard(TotalLine, 8 * 512) == (long)1)
{
MessageBox.Show("Enable card error");

}

LINESTRUCT[] Lines;

Lines = new LINESTRUCT[TotalLine];
for(short i=0; i<TotalLine; i++)
{
Lines[i].nType = (CHANNEL_TYPE)D160A.CheckChType(i);
Lines[i].State = (CHANNEL_STATE)0;
Lines[i].CallerID = "";
Lines[i].Dtmf = "";

//Lines[i].CallerID = new byte[32];


//ChnlState_LV.Items.Add(i.ToString());
//ChnlState_LV.Items[i].SubItems.Add(Lines[i].nType.ToString());
//ChnlState_LV.Items[i].SubItems.Add(Lines[i].State.ToString());
//ChnlState_LV.Items[i].SubItems.Add("");
//ChnlState_LV.Items[i].SubItems.Add("");
//ChnlState_LV.Items[i].SubItems.Add("");
}

D160A.SetBusyPara((short)350);
D160A.Sig_Init(0);
timer1.Enabled = true;
}

public void DoWork()
{
D160A.PUSH_PLAY();
D160A.FeedSigFunc();


byte[] FileName;
char[] TmpFilePath;
short TmpDTMF;

for(short i=0; i<TotalLine; i++)
{
DrawState(i);
switch(Lines[i].State)
{
case CHANNEL_STATE.CH_FREE:
if(D160A.RingDetect(i) == true)
{
if(Lines[i].nType == CHANNEL_TYPE.User)
{
D160A.OffHook(i);
Lines[i].State = CHANNEL_STATE.CH_OFFHOOK;
}
else
{
Lines[i].State = CHANNEL_STATE.CH_RECEIVEID;
D160A.ResetCallerIDBuffer(i);
Lines[i].nTimeElapse = 0;
}
}
break;
case CHANNEL_STATE.CH_RECEIVEID:
byte[] TmpCID = new byte[32];
int iResult = 0;
iResult = D160A.GetCallerIDStr(i, TmpCID);
if(iResult == 3)
{
for(int j=0; j<TmpCID.Length; j++)
{
Lines[i].CallerID = Lines[i].CallerID + ((char)TmpCID[j]).ToString();
}

D160A.OffHook(i);
//D160A.StartSigCheck(i);
Lines[i].State = CHANNEL_STATE.CH_OFFHOOK;
}
break;
case CHANNEL_STATE.CH_WAITSECONDRING:
break;
case CHANNEL_STATE.CH_OFFHOOK:
D160A.InitDtmfBuf(i);
StartPlayFileEx(i, "start.001");
Lines[i].State = CHANNEL_STATE.CH_WELCOME;
break;

case CHANNEL_STATE.CH_WELCOME:
TmpDTMF = D160A.GetDtmfCode(i);
if(TmpDTMF != -1)
{
D160A.StopPlayFile(i);
Lines[i].Dtmf = Lines[i].Dtmf + CvtDTMF(TmpDTMF);//TmpDTMF.ToString();
Lines[i].State = CHANNEL_STATE.CH_CHOOSE1;
}
if(D160A.CheckPlayEnd(i))
{
D160A.StopPlayFile(i);
StartPlayFileEx(i, "start.007");
Lines[i].State = CHANNEL_STATE.CH_CHOOSE;
}
break;


default:
break;

}
}
}



private void StartPlayFileEx(short wChnlNo, string FileName)
{
byte[] FName = GetFilePath(FileName);
D160A.StartPlayFile(wChnlNo, FName, 0);
}

private byte[] GetFilePath(string FileName)
{
TC_INI_TYPE SysInfo = new TC_INI_TYPE();
char[] TmpFName = new char[128];
byte[] FName = new byte[128];
long Pos = 0;
long tmp = 0;

D160A.GetSysInfo(ref SysInfo);
SysInfo.cbDir.CopyTo(TmpFName, 0);
Pos = SysInfo.cbDir.LongLength;
for(short j=0; j<Pos; j++)
{
if(SysInfo.cbDir[j] != 0)
tmp++;
}
Pos = tmp;
//Pos = (long)TmpFName.Length;
@"Voc\".ToCharArray().CopyTo(TmpFName, Pos);
FileName.ToCharArray().CopyTo(TmpFName, Pos+4);

short i = 0;

for(i=0; i<TmpFName.Length; i++)
{
FName[i] = (byte)TmpFName[i];
}
return FName;
}


可调试的时候显示找不到TotalLine Lines 那里又出错了呢?高手们帮帮忙啊!


2006-08-10 19:04
noshow
Rank: 2
等 级:新手上路
威 望:4
帖 子:1127
专家分:0
注 册:2006-4-21
收藏
得分:0 
那2个变量声明都是在一个方法内的
作用范围应该局限于那个方法
外方法是无法掉用的
你得把声明提到外边去

此号自封于2006年11月30日
2006-08-11 10:05
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 

我把声明提到外面去了,可调试时又显示非静态的字段 方法 或属性"luyin1.Class2.Lines"要求对象引用

还有就是在主程序里调用方法时只有www方法没有DoWork方法


怎么办?郁闷中....

2006-08-11 12:17
快速回复:急!关于类调用类!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019064 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved