Click here to Skip to main content
15,886,919 members
Home / Discussions / C#
   

C#

 
GeneralCombo Box problem... Pin
je_gonzalez7-Feb-04 17:27
je_gonzalez7-Feb-04 17:27 
GeneralDatabase Pin
ASGill7-Feb-04 17:16
ASGill7-Feb-04 17:16 
GeneralRe: Database Pin
Heath Stewart7-Feb-04 18:50
protectorHeath Stewart7-Feb-04 18:50 
GeneralMore Thread Troubles; not sure if it's deadlock Pin
Peter Mills7-Feb-04 14:41
Peter Mills7-Feb-04 14:41 
GeneralRe: More Thread Troubles; not sure if it's deadlock Pin
Heath Stewart7-Feb-04 18:58
protectorHeath Stewart7-Feb-04 18:58 
GeneralWell it's got me stumped Pin
Rob Manderson7-Feb-04 14:08
protectorRob Manderson7-Feb-04 14:08 
GeneralRe: Well it's got me stumped Pin
Rob Manderson7-Feb-04 16:25
protectorRob Manderson7-Feb-04 16:25 
GeneralRe: Well it's got me stumped Pin
Heath Stewart7-Feb-04 19:08
protectorHeath Stewart7-Feb-04 19:08 
You don't need to use an unsafe context. Instead of using byte* just use ref byte; ref and out should typically be used for pointers to value types, while they shouldn't be used for reference types - since they're already references - exception when a pointer to a pointer is needed.

Instead of declaring your param as an IntPtr for your struct or enum, you can typically use the ref keyword as well. Take, for example, the typical declaration of SendMessage:
[DllImport("user32.dll")]
private static extern IntPtr SendMessage(IntPtr hWnd, int handle,
  IntPtr wParam, IntPtr lParam);
This means that if you want to pass a pointer to a struct (say, for a window message to a common control) that you have to use the method Marshal.StructureToPtr and then pass it. Instead, a much easier - and perfectly ligitimate - alternative would be like so:
[DllImport("user32.dll")]
IntPtr SendMessage(IntPtr hWnd, int msg,
  ref MyStruct wParam, IntPtr lParam);
All this is done without requiring an unsafe context, which is typically only useful for when you have to perform address references or allocate memory for native calls without using CoTaskMemAlloc or GlobalAlloc (which are available from the Marshal as managed calls).

Keep these things in mind, remember that enums are value types too, and you should find a better, easier alternative.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Well it's got me stumped Pin
Rob Manderson7-Feb-04 22:25
protectorRob Manderson7-Feb-04 22:25 
GeneralRe: Well it's got me stumped Pin
Heath Stewart8-Feb-04 5:40
protectorHeath Stewart8-Feb-04 5:40 
QuestionHow to make panel scroll when scrollbar is moved? Pin
rul3037-Feb-04 13:45
rul3037-Feb-04 13:45 
AnswerRe: How to make panel scroll when scrollbar is moved? Pin
Heath Stewart7-Feb-04 19:12
protectorHeath Stewart7-Feb-04 19:12 
GeneralRe: How to make panel scroll when scrollbar is moved? Pin
rul3038-Feb-04 7:02
rul3038-Feb-04 7:02 
GeneralRe: How to make panel scroll when scrollbar is moved? Pin
Heath Stewart8-Feb-04 7:07
protectorHeath Stewart8-Feb-04 7:07 
GeneralGUID Conversion Pin
Tristan Rhodes7-Feb-04 8:34
Tristan Rhodes7-Feb-04 8:34 
GeneralRe: GUID Conversion Pin
Heath Stewart7-Feb-04 19:19
protectorHeath Stewart7-Feb-04 19:19 
GeneralRe: GUID Conversion Pin
Tristan Rhodes7-Feb-04 21:08
Tristan Rhodes7-Feb-04 21:08 
GeneralRe: GUID Conversion Pin
leppie7-Feb-04 23:23
leppie7-Feb-04 23:23 
GeneralRe: GUID Conversion Pin
Heath Stewart8-Feb-04 5:32
protectorHeath Stewart8-Feb-04 5:32 
GeneralRe: GUID Conversion Pin
Tristan Rhodes8-Feb-04 8:36
Tristan Rhodes8-Feb-04 8:36 
GeneralRe: GUID Conversion Pin
Nick Parker8-Feb-04 5:45
protectorNick Parker8-Feb-04 5:45 
GeneralCreating an instance of an object ... Pin
Andres Coder7-Feb-04 7:36
Andres Coder7-Feb-04 7:36 
GeneralRe: Creating an instance of an object ... Pin
Nick Parker7-Feb-04 7:56
protectorNick Parker7-Feb-04 7:56 
GeneralRe: Creating an instance of an object ... Pin
Charlie Williams7-Feb-04 8:26
Charlie Williams7-Feb-04 8:26 
GeneralRe: Creating an instance of an object ... Pin
John Kuhn7-Feb-04 8:34
John Kuhn7-Feb-04 8:34 

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.