IntPtr idp= IntPtr.Zero;
StringBuilder idata = new StringBuilder("000000");
string idata ="000000";
我这样建立的2个idata字符串,如何让idp指向他
我指向他的目的是为了传递给dll的某个函数,他需要传指针
还有我定义了一个结构如何向dll的函数传递其指针?
http://community.csdn.net/Expert/topic/5612/5612998.xml?temp=.9482843http://community.csdn.net/Expert/topic/5614/5614773.xml?temp=.5012018
所有分了,解决一起结了。
StringBuilder idata = new StringBuilder("000000");
string idata ="000000";
我这样建立的2个idata字符串,如何让idp指向他
我指向他的目的是为了传递给dll的某个函数,他需要传指针
还有我定义了一个结构如何向dll的函数传递其指针?
http://community.csdn.net/Expert/topic/5612/5612998.xml?temp=.9482843http://community.csdn.net/Expert/topic/5614/5614773.xml?temp=.5012018
所有分了,解决一起结了。
unsafe
{
fixed(char* p = &charArray[0])
{
//p就是字串首地址
}
}
public static extern int GetWindowText(IntPtr hWnd,
StringBuilder lpString, int nMaxCount);private void button1_Click(object sender, EventArgs e)
{
StringBuilder vStringBuilder = new StringBuilder(256);
GetWindowText(Handle, vStringBuilder, vStringBuilder.Capacity);
Console.WriteLine(vStringBuilder.ToString());
}
我想用IntPtr取出当前字符串的指针然后传递到我将要用到的dll函数中,然后这个dll函数会根据这指针对这个StringBuilder 进行读取写入操作,然后返回其值c#环境中进行操作
==============================================
指向StringBuilder 暂时先不管他,因为我用IntPtr idp= IntPtr.Zero;
这idp是0得值也可以调用该函数,而且这函数返回值我先略过去
现在我想让IntPtr idp= IntPtr.Zero作为一个结构的指针传递到dll中去又出现问题了。
问题估计是一种情况,就是我在c#里声明的无论字符串也好结构也好,哪怕传递了ref 进去照样是"写保护"的,dll是无法进行写操作的,我该怎么往里传递呢?
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 6)]
public String htid;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2)]
public String htdmy;
public long adv;
public long fileno;
public long filesize;
public long jobcmd;
public long datatype;
}这结构
函数里面需要调用c原形这样 Function :
After polling, acquire the table data stored the communication management information. When the first data after polling is acquired, call this command. Call hst_getcinfnext by the next programming.
Form:
int hst_getcinffirst(CINFTBL *cinftbl)
Parameter:
typedef struct CINFTBL { Data acquirement territory for the stored table of the
communication management information.
UCHAR htid[6] ID letter line
Set ID letter line of dt700/750 in sending management.
UCHAR htdmy[2] Dummy
This command is no meaning.
long adv Priority Order
Priority order is set.
long fileno File number
Set the sending file number in requesting the sending file from dt700/750.
long filesize Total of file size
Set the total sending file in requesting the sending file from dt700/750.
long jobcmd Management request command
Set the management command requested from dt700/750 in establishing the
data linking.
0:file receiving(PC←HT)、1:file sending(PC→HT)、
255:cutting request
long datatype Kind of data
Set the kind of the objected data requested the management fromdt700/750.
} cinftbl
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(HandleRef hWnd, int msg, ref int wParam, ref int lParam);
如果Api方法需要返回这个参数,那么就用ref string paramname来定义参数。
IntPtr p = Marshal.StringToHGlobalAnsi(s);