|
They are all inptr. Any pointer has the same space in memory, as it's a memory address. Then you need to marshall the intptr in your managed code to get the data it's pointing to. A char * is different, it's a string. So, a char ** is a pointer to a string. Hence, an IntPtr.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I tend to disagree somewhat. For value types a single indirection can easily be accomplished using the ref keyword; I do use IntPtr for reference types that either got fixed or GCHandle-pinned (with the exception for strings).
Here is a working example:
[DllImport("kernel32.dll")]
public static extern int GetDiskFreeSpaceEx(string rootPathName,
ref long lpFreeBytesAvailable, ref long lpTotalNumberOfBytes,
ref long lpTotalNumberOfFreeBytes);
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Yes, that would clearly work, hence, my 5
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
One note to this - if you're passing a string into unmanaged code that's going to be written to, you should use a StringBuilder instead of a string.
|
|
|
|
|
I do. It even is my favorite way of returning a string: just pass a SB with sufficient capacity and have it filled.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
|
Hi
I have created a web service, and I need to pass this data into a named pipe stream, which connects to an external device.
My web service is working well, and I have a method to retrieve data from the web service, which I can bound to a datagrid successfully. This tells me it is working correctly, and I can see my data.
However, where I am stuck is how to convert the data from the web service into either a string or bytes for the pipe to use and what is best way place the data on a named pipe in .Net?
Can anyone show me how to do this?
Thanks
|
|
|
|
|
Hi everybody.
I'm using Crystal Reports in my Win App project.
I want to execute my application on other computers.
I'd like to know , I have to install Crystal Report on destinations computers ? if so, where can I find the installer ?
Thanks.
|
|
|
|
|
Hi
I have an application which uploads files over FTP. I create a new thread and start uploading on that thread but GUI locks while this upload takes place. As far as I know because I am not uploading on main thread GUI should not lock and it should stay responsive.
What am I doing wrong? If you need the code please tell me.
Thanks.
|
|
|
|
|
it would be wrong to:
- have an event handler start the thread and wait for it to finish;
- have the thread touch any Control or windows-related Component, including Windows.Forms.Timer; this[^] explains it.
If neither apply, we will need to see some code.
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Ah!!! there you are... just gave him the link to your one of the replies yesterday
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you for your answer. My thread is interacting with a progressbar. What would be the correct way to interact with the progressbar without locking the GUI?
|
|
|
|
|
why don't you read what I gave you?
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Oh, sorry somehow I didn't see the link, it's getting late here .
I am reading the article now.
|
|
|
|
|
Thank you for showing me that article. It really helped me.
|
|
|
|
|
SimpleData wrote: What am I doing wrong? If you need the code please tell me.
You should rather try to use Backgroundworker [^]class.
In between, you should also read a great reply from Luc [^]to one one the questions couple of days back. This would also help you get you things clear.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Thank you for your answer but your second link is the same as first.
|
|
|
|
|
Sorry, for the wrong link. This [^]is the one.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
excuse me, but I don't feel responsible for that MS link at all...
Luc Pattyn
Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
Luc Pattyn wrote: excuse me, but I don't feel responsible for that MS link at all
Oops!!! I meant this [^]
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
Hi,
i am trying to make a simple bot using IE automation. i just want to register in one site using my program, but it needs captcha, i am using decaptcher.com for it. it is ok.
after web page openning, in view source of page i get one captcha link. whenever i save this image using c# program, it just redirect and save image is changed as in browser. i think you can understand what i am saying.
Is there any way to save browser image without redirecting? if i just right click in browser, manually then i am able to save image same as.
Any one can help me out??
thanks!
yogesh
|
|
|
|
|
Hello,
I'm programming a new c# application intended to control some hardware trough an ActiveX control. Given that I dont have the actual hardware, my client has provided me with a simulator OCX. The OCX is written in vb6 and it is supposed to read a status word from the registry and to fire an event whenever that word changes (that's accomplished by poling the registry, with a timer control inside the ocx). I've been also given a configurator program, which writes new values to the registry and a test program, which is a form application that consumes the ocx, both of them written in vb6 as well. At this point, everything works perfectly.
The problem arises when I want to use the OCX within a .net winforms application. I've simply referenced the control (visual studio created the wrappers), inserted it in a form and set up the corresponding event handler, which writes the status word to a label control. I've noticed that, very often, the changes in the registry are missed by the control and the corresponding event is not fired. I've confirmed this by using sysinternals regmon to watch the new values being actually written to the registry, and there seem not to be any problem in that matter.
Did anybody have a similar problem?
I would really appreciate any help.
Thanks in advance,
Bernabé
|
|
|
|
|
This is sort of a repost, but I realized after the original post that I was really asking a c# question, not a .NET framework question.
I have the need to change 'this' from one object to another.
Back ground is that I am deserializing some objects that I may already have in memory. If I identify an object as already existing, I want to deserialize directly onto that object, as opposed to deserializing onto a new object and then transfering the values.
1) I can not just use the new object because other objects that were not serialized may have links to the original object, and I don't know them all to change them.
2) The code is already unsafe , so I can't hurt it any more.
Richard
Silver member by constant and unflinching longevity.
|
|
|
|
|
Changing "this" isn't really what you're asking for. If I'm reading this correctly, what you really want to do is overwrite one object's memory with another, so references don't have to be changed.
I would actually advise against this... It would be much easier to do with a simple wrapper class.
public class MyDataObject
{
public SerializableObject Data { get; set; }
public class SerializableObject
{
}
}
So all of your references would be to the instance of MyDataObject, and those would never change... When you deserialize, you set the Data property to the new object, and it works as well as a direct replacement.
If you want to make it more transparent, you can hide the inner object entirely, and make methods and properties in the wrapper that pass through to the inner object.
|
|
|
|
|
I know I can make a variable global to a class. But What I want to do is set a variable under program.cs where "static void Main(string[] args)" Exists. In this class I want to run a initialization process to activate some variables with values I can call from any point in the application. Such as say a System Code. Is there a means of making a variable global to allow for all classes to see the variable.
My current understanding is this is not possible. Only with in classes unless you pass the variable to the other class. Is this correct?
|
|
|
|