Click here to Skip to main content
15,902,112 members
Home / Discussions / C#
   

C#

 
GeneralRe: save datagrid Pin
Heath Stewart1-Apr-04 5:56
protectorHeath Stewart1-Apr-04 5:56 
GeneralInterop Question. Again... Pin
DrGreen1-Apr-04 3:15
DrGreen1-Apr-04 3:15 
GeneralRe: Interop Question. Again... Pin
Dave Kreskowiak1-Apr-04 3:41
mveDave Kreskowiak1-Apr-04 3:41 
GeneralRe: Interop Question. Again... Pin
DrGreen1-Apr-04 3:57
DrGreen1-Apr-04 3:57 
GeneralRe: Interop Question. Again... Pin
Dave Kreskowiak1-Apr-04 4:11
mveDave Kreskowiak1-Apr-04 4:11 
GeneralRe: Interop Question. Again... Pin
Heath Stewart1-Apr-04 5:39
protectorHeath Stewart1-Apr-04 5:39 
GeneralRe: Interop Question. Again... Pin
DrGreen1-Apr-04 6:06
DrGreen1-Apr-04 6:06 
GeneralRe: Interop Question. Again... Pin
Heath Stewart1-Apr-04 6:23
protectorHeath Stewart1-Apr-04 6:23 
Nope. I use them all the time. Interop in .NET is what I focus on primarily, just see my article on Java/.NET interop without using web services or remoting, right in the presentation layer.

So true is bad in this case (it would be necessary for repeat calls using the same allocated memory).

One thing, the DWORD_PTR should be an IntPtr, which gets marshalled as a UnmanagedType.SysInt automatically by the CLR. A DWORD_PTR uses the same bit-length as an integer on the target platform, i.e. 32-bits on a 32-bit processor, 64-bits on a 64-bit processor, etc. The rest are fine, but you should consider using CharSet=CharSet.Ansi in the StructureLayoutAttribute instead of marshalling the individual fields. Just makes it much easier to read.

Also, a lot of your consts are defined as ulong (aka UInt64). When you see LONG or ULONG in native API documentation, it's still a 32-bit integer. You might be getting some overflow problems.

Finally, your mciSendCommand should look like this:
[DllImport("winmm.dll")]
[return:MarshalAs(UnmanagedType.U4)]
private static extern int mciSendCommand(
  [MarshalAs(UnmanagedType.U4)] int deviceID,
  [MarshalAs(UnmanagedType.U4)] int msg,
  [MarshalAs(UnmanagedType.U4)] int command,
  IntPtr param);
If you'll always be using this to send the MCI_OPEN_PARAMS structure, you can declare it as the following, or add the following as an overload:
[DllImport("winmm.dll")]
[return:MarshalAs(UnmanagedType.U4)]
private static extern int mciSendCommand(
  [MarshalAs(UnmanagedType.U4)] int deviceID,
  [MarshalAs(UnmanagedType.U4)] int msg,
  [MarshalAs(UnmanagedType.U4)] int command,
  ref MCI_OPEN_PARAMS);
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct MCI_OPEN_PARAMS
{
  public IntPtr callback;
  [MarshalAs(UnmanagedType.U4)] public int deviceID;
  public string deviceType;
  public string elementName;
  public string alias;
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Interop Question. Again... Pin
DrGreen1-Apr-04 6:33
DrGreen1-Apr-04 6:33 
GeneralRe: Interop Question. Again... Pin
leppie1-Apr-04 6:17
leppie1-Apr-04 6:17 
GeneralRe: Interop Question. Again... Pin
Heath Stewart1-Apr-04 6:30
protectorHeath Stewart1-Apr-04 6:30 
GeneralRe: Interop Question. Again... Pin
leppie1-Apr-04 6:10
leppie1-Apr-04 6:10 
GeneralRe: Interop Question. Again... Pin
DrGreen1-Apr-04 6:20
DrGreen1-Apr-04 6:20 
GeneralC# listbox, combobox trouble Pin
abidkayani11-Apr-04 2:49
abidkayani11-Apr-04 2:49 
GeneralC # problem (app block) Pin
abidkayani11-Apr-04 2:43
abidkayani11-Apr-04 2:43 
GeneralRe: C # problem (app block) Pin
Mazdak1-Apr-04 2:59
Mazdak1-Apr-04 2:59 
GeneralRe: C # problem (app block) Pin
abidkayani11-Apr-04 12:15
abidkayani11-Apr-04 12:15 
GeneralC# problem Pin
abidkayani11-Apr-04 2:41
abidkayani11-Apr-04 2:41 
GeneralRe: C# problem Pin
Mazdak1-Apr-04 2:54
Mazdak1-Apr-04 2:54 
GeneralRe: C# problem Pin
Heath Stewart1-Apr-04 5:31
protectorHeath Stewart1-Apr-04 5:31 
GeneralTreeView copy Pin
Ata Özçelik1-Apr-04 2:19
Ata Özçelik1-Apr-04 2:19 
GeneralRe: TreeView copy Pin
Dave Kreskowiak1-Apr-04 3:32
mveDave Kreskowiak1-Apr-04 3:32 
GeneralShow some specific region of form Pin
Itanium1-Apr-04 0:42
Itanium1-Apr-04 0:42 
GeneralRe: Show some specific region of form Pin
Dave Kreskowiak1-Apr-04 2:23
mveDave Kreskowiak1-Apr-04 2:23 
Generalgetting binary resources Pin
mhmoud rawas31-Mar-04 23:49
mhmoud rawas31-Mar-04 23:49 

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.