Click here to Skip to main content
15,900,438 members
Home / Discussions / C#
   

C#

 
QuestionButton control ? Pin
Christian Graus30-Jan-05 9:48
protectorChristian Graus30-Jan-05 9:48 
AnswerRe: Button control ? Pin
Robert Rohde30-Jan-05 19:01
Robert Rohde30-Jan-05 19:01 
GeneralGet an Image from an ImageList Pin
Luis Alonso Ramos30-Jan-05 9:44
Luis Alonso Ramos30-Jan-05 9:44 
GeneralRe: Get an Image from an ImageList Pin
Yulianto.30-Jan-05 22:36
Yulianto.30-Jan-05 22:36 
GeneralRe: Get an Image from an ImageList Pin
Luis Alonso Ramos31-Jan-05 5:24
Luis Alonso Ramos31-Jan-05 5:24 
GeneralDirect3D in a panel makes VS Designer hang Pin
iammudman30-Jan-05 8:52
iammudman30-Jan-05 8:52 
GeneralRe: Direct3D in a panel makes VS Designer hang Pin
Skynyrd30-Jan-05 14:24
Skynyrd30-Jan-05 14:24 
GeneralPlease Help Pin
Beringer30-Jan-05 5:59
Beringer30-Jan-05 5:59 
I am trying to access some functionality of the underlying RichTextBox
control and am getting all mixed up with conversions of types. I know my
basic issue is not completely understanding types in C#. I would
be much obliged if someone could "educate" me some. I appoligize already for the
amount of text in this message. Italic text is unmanged code and bold text is my
attempt to write the same thing in C#.

Since I need to use the SendMessage of User32.dll I defined the following:

[DLLImport ("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr
wParam, IntPtr lParam);


Then I'm trying to create the equivalent code in C# for the following
callback function:

DWORD EditStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG
*pcb);


by defining the following delegate:

public delegate UInt32 EditStreamCallback(IntPtr dwCookie, IntPtr pbBuff,
Int32 cb, IntPtr pcb);


That seems to work well (at least for the compiler).
I then "translated" the following typedef:

typedef struct _editstream {
DWORD_PTR dwCookie;
DWORD dwError;
EDITSTREAMCALLBACK pfnCallback;
} EDITSTREAM


into the following structure:

private struct EDITSTREAM {
public IntPtr dwCookie;
public UInt32 dwError;
public EditStreamCallback pfnCallback;
}


So with all the definitions out of the way I thought I could do something
like this:
...

FileStream fs = new FileStream(Filename, FileMode.Open);
int format = SF_RTF;EDITSTREAM es = new EDITSTREAM();
es.dwCookie = (IntPtr)fs;
es.pfnCallback = new EditStreamCallback(StreamIn);
SendMessage(this.Handle, EM_STREAMIN, (IntPtr)format, (IntPtr)es);

...


but now the complier isn't happy and I get "Cannot convert type 'x' to
System.IntPtr" errors where I try to cast to IntPtr. It was my
understanding the "new" creates a reference type (i.e. memory address,
e.g. pointer) So, why can't I cast to IntPtr here? It is interesting to
note that there is no error on the cast of "format". Now on the flip side
I have the following code:

static UInt32 StreamIn(IntPtr dwCookie, IntPtr pbBuff, Int32 cb, IntPtr
pcb)
{
UInt32 result = 0;
FileStream fs = (FileStream)dwCookie;
pcb = cb;
try
{
pcb = fs.Read((byte[])pbBuff, 0, cb);
}
catch (Exception e)
{
pcb = 0;
result = 1;
}
return result;
}


This is the callback function delegate used above. I get compile time
errors at the attempted unboxing of dwCookie and pbBuff.
Also there is an error at pcb = cb ("cannot implictly convert int to IntPtr")

I know I am asking alot here but I am really stuck and since I'm trying to learn C# on
my own I could really use some help. Am I correct in using IntPtr for the changes in types
from the Unmanaged code to C#?

Thank you in advance,

Eric
Generaldirectives in c# for .net version Pin
Clickok30-Jan-05 5:35
Clickok30-Jan-05 5:35 
GeneralRe: directives in c# for .net version Pin
Mazdak30-Jan-05 6:02
Mazdak30-Jan-05 6:02 
GeneralRe: directives in c# for .net version Pin
Clickok30-Jan-05 6:17
Clickok30-Jan-05 6:17 
QuestionMonitor all key press??? Pin
bmk_shepherd30-Jan-05 2:46
bmk_shepherd30-Jan-05 2:46 
AnswerRe: Monitor all key press??? Pin
Stefan Troschuetz30-Jan-05 4:13
Stefan Troschuetz30-Jan-05 4:13 
GeneralUpdateResource API Call Pin
Wayne Phipps30-Jan-05 2:45
Wayne Phipps30-Jan-05 2:45 
GeneralRe: UpdateResource API Call Pin
Michael Dunn30-Jan-05 8:09
sitebuilderMichael Dunn30-Jan-05 8:09 
GeneralRe: UpdateResource API Call Pin
Wayne Phipps1-Feb-05 9:07
Wayne Phipps1-Feb-05 9:07 
GeneralDirectory.GetLogicalDrives() Question Pin
QzRz30-Jan-05 2:22
QzRz30-Jan-05 2:22 
GeneralRe: Directory.GetLogicalDrives() Question Pin
mav.northwind30-Jan-05 2:42
mav.northwind30-Jan-05 2:42 
GeneralRe: Directory.GetLogicalDrives() Question Pin
CiNN30-Jan-05 12:40
CiNN30-Jan-05 12:40 
GeneralRe: Directory.GetLogicalDrives() Question Pin
mav.northwind30-Jan-05 20:19
mav.northwind30-Jan-05 20:19 
Generalget child of windows Pin
students552 university29-Jan-05 17:12
students552 university29-Jan-05 17:12 
GeneralRe: get child of windows Pin
eggie529-Jan-05 19:20
eggie529-Jan-05 19:20 
GeneralHTTP Post Request Pin
notacake29-Jan-05 12:41
notacake29-Jan-05 12:41 
GeneralRe: HTTP Post Request Pin
eggie529-Jan-05 13:08
eggie529-Jan-05 13:08 
GeneralRe: HTTP Post Request Pin
notacake30-Jan-05 1:06
notacake30-Jan-05 1:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.