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

我建了一个项目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
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
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
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 

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

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


怎么办?郁闷中....

2006-08-11 12:17
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 

谢谢楼伤的高人指点,那三个变量终于不出错了,可是关于上面类里面一个private方法

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;
}

调试时出现以下错误:

命名空间并不直接包含诸如字段或方法之类的成员
应输入 class、delegate、enum、interface 或 struct
应输入 class、delegate、enum、interface 或 struct
应输入 class、delegate、enum、interface 或 struct
应输入 class、delegate、enum、interface 或 struct
应输入标识符
应输入标识符
应输入标识符
应输入标识符
应输入标识符
应输入类型、命名空间定义或文件尾

哎!这里不乱那里就乱简直想自杀的说!

2006-08-11 16:02
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 
G:\wuyang\cti\c#vs.net\luyin1\Class2.cs(53): “luyin1.Class2.www()” : 并非所有的代码路径都返回值
G:\wuyang\cti\c#vs.net\luyin1\Class2.cs(218): 变量“strTmp”已赋值,但其值从未使用过
G:\wuyang\cti\c#vs.net\luyin1\Class2.cs(109): 声明了变量“FileName”,但从未使用过
G:\wuyang\cti\c#vs.net\luyin1\Class2.cs(110): 声明了变量“TmpFilePath”,但从未使用过


声明了变量没有使用问题应该不大吧,道是说方法www那句是什么意思啊?那里就定义了一些初始化函数要怎么解决上面的错误呢?
2006-08-11 17:43
wuyangmouse
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2006-8-4
收藏
得分:0 

是哦,我不知道怎么返STRING型就把它改成VOID了,程序是调通了可是放音功能没实现

我在public class Form1 : System.Windows.Forms.Form里添加了一个 ListView控件listView1,在www方法里有代码

      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("");
在DrawState方法里有代码
      if(ChnlState_LV.Items[wChnlNo].SubItems[2].Text = Lines[wChnlNo].State.ToString())
ChnlState_LV.Items[wChnlNo].SubItems[2].Text = Lines[wChnlNo].State.ToString();

if(ChnlState_LV.Items[wChnlNo].SubItems[3].Text != Lines[wChnlNo].CallerID)
ChnlState_LV.Items[wChnlNo].SubItems[3].Text = Lines[wChnlNo].CallerID;

if(ChnlState_LV.Items[wChnlNo].SubItems[4].Text != Lines[wChnlNo].Dtmf)
ChnlState_LV.Items[wChnlNo].SubItems[4].Text = Lines[wChnlNo].Dtmf;

if(ChnlState_LV.Items[wChnlNo].SubItems[5].Text != strTmp)
ChnlState_LV.Items[wChnlNo].SubItems[5].Text = strTmp;


这两段代码写在封装的类的方法里也不对写在public class Form1 : System.Windows.Forms.Form里也出错,到底应该写在那里呢?高人们帮忙看一下啊!

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



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

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