|
Hi,
Sorry if this is too basic, Can you please let me know how to typecast string to char* in C#? I need this as Im calling a managed DLL function.
Thanks
Vikas
|
|
|
|
|
Do you mean char[] ?
string s = "abc";
char[] c = s.ToCharArray();
|
|
|
|
|
|
"Managed" ???
Do you want to use pointer in managed environment ???
|
|
|
|
|
Actually from C# I'm calling an unmanaged MFC DLL.
MFC DLL has an API for example:
<br />
int fnSetMonitorNo(char* m_MonitorNo)<br />
int fnGetMonitorNo(char* m_MonitorNo)<br />
If I pass char* to the DLL, it will see the MonitorNo. I tried to do in C# as follows
[DllImport("OfficeCTE.dll")]<br />
public static extern unsafe int fnSetMonitorNo([MarshalAs(UnmanagedType.LPStr)]string arg1);<br />
<br />
[DllImport("OfficeCTE.dll")]<br />
public static extern unsafe int fnGetMonitorNo([MarshalAs(UnmanagedType.LPStr)]string arg1); <br />
But it didn't work.
How can this be done?
|
|
|
|
|
Vikas K. wrote: Im calling a managed DLL function
I don't think that you will be using pointers much in managed environment.
Vikas K. wrote: string to char*
If you want to call some native C++ functions you can use Marshal.StringToHGlobalAnsi[^] method.
*jaans
|
|
|
|
|
hi
i want to detect sql server instances on the system, i was use System.Data.Sql.SqlDataSources
it was work correctly, but does not detect local or default instances, i want to detect it by wmi(like sql server 2005 configuraion manager), but how to do ?
thanks
|
|
|
|
|
Hi all,
I have one resource file and i want to update and delete the content from the resource file programetically, but when i update the resource file thru one form then it will insert the new record rather than update. Below is my code.
ResXResourceWriter w = new ResXResourceWriter("ResXForm.resx");<br />
w.AddResource("test", "test123");<br />
w.Generate();<br />
w.Close();
And when i insert the record programetically, at that time it will insert the record, but it will overright the previous record. how it is possible ?
Rana Krishnraj
|
|
|
|
|
So let's see here ... you execute an AddResource and yet you cannot figure out why it is ADDING the record instead of updating????
I suggest you find another career or go back to school. But if you insist on remaining a programmer, then I just gave you the clue to your answer.
|
|
|
|
|
Hey,
i know i use addsource but u know what happen is ??
suppose i have 4 records in my resource file and when i add new record programetically at that time it will erase previous 4 records and add new i records so right now i have only one records in my resource file. so understand it will not append the records.
i know its my mistake in asking question but from now do not use this kind of words ok..
and if u don't know then do not reply with this kind of words understand.
Rana Krishnraj
|
|
|
|
|
The very, very basic process of changing an element in an array:
resource["text"] = "test 123";
|
|
|
|
|
Doing a little googling I find that you have done two things wrong.
First you defined your FileStream wrong. You have it set of Create or Open and do not have it set for ReadWrite
Next you are only using AddResource for everything. Look at AddResourceData.
If none of those help then you are SOL. And while you may not like what I say, I do not like jobs stolen by cheap Indian labor and then having the same job theives coming here begging us to write their code for them or help them become programmers.
|
|
|
|
|
OK Now don't explain me in air ok. Doing a little googling is not enough ok and one more thing when u make an object of ResXResourceWriter and after that try yo find object's associated methode. there is no any kind of methode that u specufy - AddResourceData() understand u SOL.
any way i already implement it. From now don't reply to any body with this kind of words understand u Bhenchode..
Rana Krishnraj
|
|
|
|
|
|
protected void btnright_Click(object sender, EventArgs e)
{
ListItemCollection listnameitems = lstboxnames.Items;
foreach(ListItem itmname in listnameitems)
{
if (itmname.Selected == true)
{
lstboxphone.Items.Add(itmname.Text);
listnameitems.Remove(itmname);
}
}
}
this is my code to select list box items of one listbox to other listbox.the items must get removed from the listbox where the items are added from.
The add method is working but when i remove the items it is showing a msg box with "collection was modified enumeration may not execute ".
Can any one help where iam doing mistake.
|
|
|
|
|
Exactly what the error says. You cannot modify a collection you are using foreach on. So, you need to use a for loop, or you need to collect items to modify and modify them outside the loop.
List<ListItem> remove = new List<ListItem>();
foreach(ListItem itmname in listnameitems)
{
if (itmname.Selected == true)
{
lstboxphone.Items.Add(itmname.Text);
remove.Add(itmname);
}
}
// now iterate over remove, and remove them.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
does i need to include any namespaces?
The type or namespace name 'List' could not be found (are you missing a using directive or an assembly reference?)
foreach statement cannot operate on variables of type 'System.Web.UI.WebControls.ListBox' because 'System.Web.UI.WebControls.ListBox' does not contain a public definition for 'GetEnumerator'
the above errors are listed when i execute code using ur reply.thanku
|
|
|
|
|
its ok i have done with for loop.
but if any other answer using for each reply me.
Thank u
|
|
|
|
|
System.Collections.Generic. VS2005 will show you missing namespaces, just put the arrow near the bottom right of the word and an arrow appears, which will add a using statement or scope it explicitly for you.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
There's a much more elegant way to do this if the collection has RemoveAll
listnameitems.RemoveAll( delegate(ListItem itemName) { return itemName.Selected; } );
This avoids creating a temporary list, adding items to it and then iterating over it and removing items from the original list.
|
|
|
|
|
Guys need help man
How to convert this vb code
officer.Text = mid(User.Identity.Name, instr(User.Identity.Name, "\")+1, len(User.Identity.Name))
to C Sharp
Thanks A million
KaKaShi HaTaKe
|
|
|
|
|
Hi,
Here is yr c# code.
officer.Text == Strings.mid(User.Identity.Name, Strings.instr(User.Identity.Name, "\\") + 1, Strings.len(User.Identity.Name))
I hope it will help u..
Rana Krishnraj
|
|
|
|
|
Krishnraj,
I don't think it will help him, since it wont work in C#.
Regards,
Gareth.
|
|
|
|
|
|
There are several websites that translate code from Vb to C# or the other way around. Google will help you in finding them if you ask it.
Giorgi Dalakishvili
#region signature
my articles
#endregion
|
|
|
|