|
I want to create an Access database with C#. Did MS leave this out??? I can do this using DAO and C++!!! Not with ADO??? Why not?
|
|
|
|
|
Look for Adox. For some reason, they don't talk about it much in any of my books.
|
|
|
|
|
Does anyone know how to get a ComboBox in a toolbar without using a third party control? I need to use the standard .NET toolbar with a combobox.
|
|
|
|
|
|
There is no equivelent method to the Windows ZeroMemory function in C#. You need to remember that the memory in C# is managed for you. What are you trying to do, maybe I can help you find a solution.
Aalst
|
|
|
|
|
|
byte buffer = new byte[size];
IntPtr ptr = Marshal.AllocHGlobal(size * Marshal.SizeOf(typeof(byte)));
Marshal.Copy(buffer, 0, ptr, size);
I dunno if this will provide the same ?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
i have discovered that when i changed the second parameter of mciSendCommand from MCI_OPEN to 0, it did not give the error, but nothing happened.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Nnamdi Onyeyiri wrote:
i have discovered that when i changed the second parameter of mciSendCommand from MCI_OPEN to 0, it did not give the error, but nothing happened.
MCI_OPEN = 0x0803;
MCI_OPEN_PARMS is a struct. What does the 2 have to do with each other?
I will have a look.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
MCI_OPEN = 0x0803;
i know that, im passing the value as 0x0803.
leppie wrote:
MCI_OPEN_PARMS is a struct. What does the 2 have to do with each other?
according to the article i gave the link for in my original post, it uses mciSendCommand(0, MCI_OPEN, flags, MyOpenParms);
but when i do this, i get the exception.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Hi , it was a bit trickey, but using int's did the job
[DllImport("winmm.dll" , CharSet = CharSet.Ansi)]
static extern int mciSendCommand(int device, int msg, int flags, int param);
const int MCI_OPEN = 0x0803;
const int MCI_DEVTYPE_CD_AUDIO = 516;
const int MCI_SET = 0x080D;
const int MCI_SET_DOOR_OPEN = 0x00000100;
const int MCI_SET_DOOR_CLOSED = 0x00000200;
[StructLayout(LayoutKind.Sequential)]
public class MCI_OPEN_PARMS
{
public int dwCallback;
public int wDeviceID;
public int lpstrDeviceType;
public int lpstrElementName;
public int lpstrAlias;
}
[Flags]
public enum MCIOPEN
{
SHAREABLE = 0x00000100,
ELEMENT = 0x00000200,
ALIAS = 0x00000400,
ELEMENT_ID = 0x00000800,
TYPE_ID = 0x00001000,
TYPE = 0x00002000,
}
and the implementation
MCIOPEN flags;
flags = MCIOPEN.TYPE | MCIOPEN.TYPE_ID | MCIOPEN.SHAREABLE;
MCI_OPEN_PARMS param = new MCI_OPEN_PARMS();
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(param));
param.lpstrDeviceType = MCI_DEVTYPE_CD_AUDIO;
Marshal.StructureToPtr(param, ptr, true);
int result = mciSendCommand(0, MCI_OPEN, (int) flags, ptr.ToInt32());
Marshal.PtrToStructure(ptr, param);
Marshal.FreeHGlobal(ptr);
result = mciSendCommand(param.wDeviceID, MCI_SET, MCI_SET_DOOR_OPEN, 0);
result = mciSendCommand(param.wDeviceID, MCI_SET, MCI_SET_DOOR_CLOSED, 0);
OK, I didnt bother with drive numbers
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
|
i know this doesn't apply if some values of your array were already changed, but the runtime asures you, that after constructing everything is set to zero.
thus
byte [] b = new byte[20];
for (int i=0; i<20; ++i)
if (b[i]!=0) MessageBox.Show("you will not see me");
runs without popping up that window.
:wq
|
|
|
|
|
And on top of all the other responses, it should be pointed out that you can always reinitialise any array with the Initialize method.
For example:
byte[] array = new byte[20];
for (int i=0;i<20;i++)
array[i] = i;
array.Initialize();
OR
string[] array = new string[20];
for (int i=0;i<20;i++)
array[i] = i.ToString();
array.Initialize();
One of these answers should help now
Paul
|
|
|
|
|
You should be able to make an "unsafe" call once you import it, something like this:
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
unsafe public static extern void ZeroMemory(System.IntPtr ptr ,uint size);
HTH
Nick Parker
|
|
|
|
|
hi, i'm stuck.
i'm currently trying to work with an old dll and marshalling and stuff went really fine until now. there's a function in that dll declared like
int foo(void *ppMessage);
the function will do some nasty stuff, allocate local memory for the result and write the pointer to the result in the parameter. (thats why there are two ps in the name)
in c++ it would be something like
byte *result;
foo(&result);
(*result)[0]
i have no idea, how to actually read the result using c# - does anyone know? looks somewhat unmanaged
thx in advance
:wq
|
|
|
|
|
ah. just found the Marshal-class - maybe this helps me...
:wq
|
|
|
|
|
First of all, are you sure about the signature of your C method ?
Isn't it more like this :
int foo(void **ppMessage);
To expose this C function to managed code, you need to declare it as :
[DllImport("user32.dll", CharSet=CharSet.Auto, CallingConvention=CallingConvention.Cdecl)]
public static extern int foo(out IntPtr ppMessage);
where user32.dll must be replaced with the actual DLL name.
And I swallow a small raisin.
|
|
|
|
|
erm no, i looked it up in the header-file and there's only one star. i'm a bit confused too, but it seems you have to know, that you get a pointer in the specified location.
actually i have solved the thing like this:
[DllImport("theold.dll")]
public static extern Int32 foo(IntPtr [] messagePtr);
...
IntPtr [] messagePtr = new IntPtr[1];
Int32 ret = foo(messagePtr);
Int16 size = Marshal.ReadInt16(messagePtr[0]);
byte [] message = new byte[size];
Marshal.Copy(messagePtr[0],message,0,size);
i know (from the specification) that the first 2 bytes contain the size of the result in bytes.
:wq
|
|
|
|
|
Hi, it seems you should be able to remove the array like:
[DllImport("theold.dll")]public static extern Int32 foo(out IntPtr messagePtr);
...
IntPtr messagePtr;
Int32 ret = foo(messagePtr);
Int16 size = Marshal.ReadInt16(messagePtr);
byte [] message = new byte[size];
Marshal.Copy(messagePtr,message,2,size);
I'm interested, does this work too?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
1. yep. out works indeed. good idea. but in the foo-call is to be inserted uswell.
2. no, the copy-call was ok, since the size-field is included (i.e. the value is at least 2 for the 2 size-bytes)
finally:
[DllImport("theold.dll")]
public static extern Int32 foo(out IntPtr messagePtr);
...
IntPtr messagePtr;
Int32 ret = foo(out messagePtr);
Int16 size = Marshal.ReadInt16(messagePtr);
byte [] message = new byte[size];
Marshal.Copy(messagePtr,message,0,size);
thx again for your help an ideas
:wq
|
|
|
|
|
Rüpel wrote:
but in the foo-call is to be inserted uswell.
oops , happens when u write the code out of your head straight into the textbox
Rüpel wrote:
2. no, the copy-call was ok, since the size-field is included (i.e. the value is at least 2 for the 2 size-bytes)
But wont the fist 2 byte values (being a size value) affect the byte[]?
(oops another typo , meant to do this)
byte [] message = new byte[size - 2];
Marshal.Copy(messagePtr,message,2,size);
or
byte [] message = new byte[size - 2];
Marshal.Copy(new IntPtr(messagePtr.ToInt32() + Marshal.SizeOf(typeof(byte))*2),message,0,size - 2);
I'm just interested
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I want to know wheather we can write components using c# in place of ATL COM.i.e..is it possible to write everything whatever we do in ATLCom.
|
|
|
|