|
Hi Leppie,
Thanks once again for the help! I will certainly look into that.
It's looks VERY interesting.
But I have already done alot of coding making the que, classes etc.
All is done by using my current threading method
But mayby its the solution..
But thanks again leppie!
Regards
|
|
|
|
|
If you are looking to track down the bug I'd recommend the allocation profiler which will give you memory snapshots (same site) and compuware's devpartner profiler might give you some insight.
|
|
|
|
|
I am looking for a way of converting a System.Type to a System.Data.SqlDbType
So when I write a type as text it gets the right SqlDbType.
for instance let's say I've got a variable a of an unknown type,
with function GetType() I can get the System.Type of a.
Now i'm looking for a way to do the same and get the right SqlDbType
of the same variable.
Any thoughts?
|
|
|
|
|
I have done just a hashtable mapping for that, anyways here's the code:
public class TypeMapping
{
static Hashtable map;
public static Hashtable Mapping
{
get {return map;}
}
static TypeMapping()
{
map = new Hashtable();
map.Add(SqlDbType.BigInt, typeof(Int64));
map.Add(SqlDbType.Binary, typeof(byte[]));
map.Add(SqlDbType.Bit, typeof(Boolean ));
map.Add(SqlDbType.Char, typeof( String ));
map.Add(SqlDbType.DateTime, typeof( DateTime ));
map.Add(SqlDbType.Decimal, typeof( Decimal ));
map.Add(SqlDbType.Float, typeof( Double ));
map.Add(SqlDbType.Image, typeof( byte[]));
map.Add(SqlDbType.Int, typeof( Int32 ));
map.Add(SqlDbType.Money, typeof( Decimal));
map.Add(SqlDbType.NChar, typeof( String ));
map.Add(SqlDbType.NText, typeof( String ));
map.Add(SqlDbType.NVarChar, typeof( String ));
map.Add(SqlDbType.Real, typeof( Single ));
map.Add(SqlDbType.SmallDateTime, typeof( DateTime ));
map.Add(SqlDbType.SmallInt, typeof( Int16 ));
map.Add(SqlDbType.SmallMoney, typeof( Decimal));
map.Add(SqlDbType.Text, typeof( String ));
map.Add(SqlDbType.Timestamp, typeof( DateTime ));
map.Add(SqlDbType.TinyInt, typeof( Byte ));
map.Add(SqlDbType.UniqueIdentifier, typeof( Guid ));
map.Add(SqlDbType.VarBinary, typeof( byte[] ));
map.Add(SqlDbType.VarChar, typeof( String ));
map.Add(SqlDbType.Variant, typeof( Object ));
}
}
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
That did the trick, Thank you very much
|
|
|
|
|
hi!
how can i draw a rectangle in a richtextbox?
thanks
|
|
|
|
|
System.Drawing.Rectangle
Exsample : System.Drawing.Rectangle jr = new System.Drawing.Rectangle(10,10,100,100);
System.Drawing.Rectangle jr = new System.Drawing.Rectangle(int X,int Y,int Width,int Height);
this code (below) might work...but i just through it together... where to see the code jr.Size it is actually suposed to be the bounds...but it might work anyway.
System.Drawing.Rectangle jr = new System.Drawing.Rectangle(10,10,100,100);<br />
System.Drawing.Graphics.FillRectangle(new SolidBrush(Color.Red),jr.Size);
Jesse M
P.s : if you are making a drawing program (which it seems like you might be) check to see if the RichTextBox class has a OwnerDraw property. this would give you OnDraw Events that you could override.
The Code Project Is Your Friend...
|
|
|
|
|
how do I translate into C#:
extern "C" int f(void*);
I know about "unsafe", but I'd like it to be a normal DLLImport
|
|
|
|
|
The IntPtr type can handle void pointers. In fact, it has static methods specifically for dealing with them.
Incidentally, "unsafe" doesn't mean "not safe to do", as the name implies. It just means the runtime cannot verify the types and such for us. I read somewhere that the name was chosen to scare unseasoned programmers away from using it. Internally, the CLR uses unsafe all the time.
Cheers
|
|
|
|
|
Jeff J wrote:
it has static methods specifically for dealing with
which one?
forgot the 2nd signature I am using
extern "C" int f2(void**);
I managed to make it work witch "ref uint" unfortunatly the first function does not take return value.
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f(uint s);
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f2(ref uint s);
After I use return value for "f()" in "f2()" I got something like "'System.Runtime.InteropServices.MarshalDirectiveException' Can not marshal parameter #1: Invalid managed/unmanaged type combination (Int/UInt must be paired with I or U)"
Any suggestions are welcome (I'll definitely try unsafe)
|
|
|
|
|
Anonymous wrote:
Jeff J wrote:
it has static methods specifically for dealing with
which one?
Ones, the ones in the Marshal class
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
As leppie posted, there are many useful functions in the Marshal class, which is good to become familiar with if you are interfacing with external C or C++ functions. IntPtr itself also has useful methods, such as ToPointer() and ToInt32(), along with the statics Zero and operator overloads that can convert between void pointers and IntPtr types. Which ones to use depends on how you plan on calling the extern functions.
It is hard to explain the usage details without seeing a code example. If you could post one with how the calls are intended to be made, and how the parameters are to be passed, I'm sure I could explain a solution.
Regarding using the extern funcs you currently have, if the calling C# func is declared unsafe, then you can just cast your "ints" as in regular C code (including pointers and taking addresses). Or you can prototype the externs as unsafe from the start like:
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern unsafe int f(void *pVoid);
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern unsafe int f2(void **ppVoid);
If you are looking to do this using the non-unsafe runtime interop features, you could do:
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f(IntPtr pVoid);
DLLImport("rv.dll", CharSet=CharSet.Ansi, CallingConvention=CallingConvention.Cdecl))
public static extern int f2(IntPtr ppVoid);
|
|
|
|
|
Hi,
I'm getting a System.ArgumentException trying to call the following
IActiveDesktop method:
STDMETHOD (AddDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
This is how I'm marshaling the call.
void AddDesktopItem(
[In, MarshalAs( UnmanagedType.LPStruct )] COMPONENT pcomp,
[In] int dwReserved
);
I believe the problem is with marshaling the COMPONENT structure. Could
some one point out to me if I'm marshaling the nested structures correctly.
Here is the original typedef for the struct and my c# attempt at marshaling
it.
typedef struct _tagCOMPONENT
{
DWORD dwSize; //Size of this structure
DWORD dwID; //Reserved: Set it always to zero.
int iComponentType; //One of COMP_TYPE_*
BOOL fChecked; // Is this component enabled?
BOOL fDirty; // Had the component been modified and not
BOOL fNoScroll; // Is the component scrollable?
COMPPOS cpPos; // Width, height etc.,
WCHAR wszFriendlyName[MAX_PATH];
WCHAR wszSource[INTERNET_MAX_URL_LENGTH]; //URL of the component.
WCHAR wszSubscribedURL[INTERNET_MAX_URL_LENGTH]; //Subscrined URL
DWORD dwCurItemState; // Current state of the Component.
COMPSTATEINFO csiOriginal;
COMPSTATEINFO csiRestored; // Restored state of the component.
}
COMPONENT;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode )]
public class COMPONENT
{
public int dwSize; // Size of the structure.
public int dwID; // Reserved. Set to zero.
public COMP_TYPE iComponentType;
[MarshalAs( UnmanagedType.Bool )]
public bool fChecked;
[MarshalAs( UnmanagedType.Bool )]
public bool fDirty;
[MarshalAs( UnmanagedType.Bool )]
public bool fNoScroll;
[MarshalAs( UnmanagedType.Struct )]
public COMPPOS cpPos;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )]
public string wszFriendlyName;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )]
public string wszSource;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )]
public string wszSubscribedURL;
public ITEM_STATE dwCurItemState;
[MarshalAs( UnmanagedType.Struct )]
public COMPSTATEINFO csiOriginal;
[MarshalAs( UnmanagedType.Struct )]
public COMPSTATEINFO csiRestored;
}
StructLayout( LayoutKind.Sequential )]
public class COMPSTATEINFO
{
public int dwSize;
public int iLeft;
public int iTop;
public int dwWidth;
public int dwHeight;
public ITEM_STATE dwItemState;
}
[StructLayout(LayoutKind.Sequential)]
public class COMPPOS
{
public int dwSize;
public int iLeft;
public int iTop;
public int dwWidth;
public int dwHeight;
public int izIndex;
[MarshalAs( UnmanagedType.Bool )]
public bool fCanResize;
[MarshalAs( UnmanagedType.Bool )]
public bool fCanResizeX;
[MarshalAs( UnmanagedType.Bool )]
public bool fCanResizeY;
public int iPreferredLeftPercent;
public int iPreferredTopPercent;
}
|
|
|
|
|
Nathan Tran wrote:
I'm getting a System.ArgumentException trying to call the following
IActiveDesktop method:
STDMETHOD (AddDesktopItem)(THIS_ LPCCOMPONENT pcomp, DWORD dwReserved) PURE;
This is how I'm marshaling the call.
void AddDesktopItem(
[In, MarshalAs( UnmanagedType.LPStruct )] COMPONENT pcomp,
[In] int dwReserved
);
I believe the problem is with marshaling the COMPONENT structure.
STOP! Its exactly what it says. Dont use LPStruct. Just add ref to it, or Marshall the structure to unmanaged memory 1st, then pass an IntPtr into the function (obviously you will need to change the function definition).
Once (and only then), you can lok at the HRESULT you are getting to see if the struct size is infact correct (which probably wont be the case, never is with these nested structs). Good luck NOT lol, where is the functions DllImportAttribute? Thats the problem. Not sure how it compiled...
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie,
I don't need the DllImportAttribute since this COM method is being called through a c# mapped interface. Based on your suggestion to use IntPtr I have made the following changes to the code but I'm still getting System.ArgumentException.
void AddDesktopItem(
[In] IntPtr component,
[In] int dwReserved
);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode )]
public class COMPONENT
{
public int dwSize; // Size of the structure.
public int dwID; // Reserved. Set to zero.
public COMP_TYPE iComponentType;
public int fChecked;
public int fDirty;
public int fNoScroll;
public COMPPOS cpPos;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 260 )]
public string wszFriendlyName;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )]
public string wszSource;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 2083 )]
public string wszSubscribedURL;
public ITEM_STATE dwCurItemState;
public COMPSTATEINFO csiOriginal;
public COMPSTATEINFO csiRestored;
}
and the help method to copy the struct to unmanaged mem is as follows.
public static IntPtr CreateByteBuffer( COMPONENT comp )
{
IntPtr bufferPtr = Marshal.AllocCoTaskMem( Marshal.SizeOf( comp ) );
Marshal.StructureToPtr( comp, bufferPtr, true );
return bufferPtr;
}
Note: I have verified that the size of the struct to be correct. It is 8972 bytes to be exact. I have even checked the memory location of the IntPtr and all the relevant data is there.
Any other suggestion?
Nathan.
|
|
|
|
|
Nathan Tran wrote:
Any other suggestion?
Maybe the C# mapping is wrong? I dont really know the COM stuff too well. Normal interop I do know well. You have thus checked that stuff and it checks out ok. That leads me back to that function, what happens from there?
Sorry couldnt help more
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Hello all,
What is the quickest way to convert an image to a byte array?
Is it image -> file -> byte array ?
Or is there a short cut ?
Thanks
Smitha
Imagination is more important than knowledge.
--Albert Einstein
|
|
|
|
|
Smitha Vijayan wrote:
What is the quickest way to convert an image to a byte array?
I am not sure if you mean performance or easiest to code, but you can just use the Image's Save method, and pass a MemoryStream instead of some sort of file stream. A MemoryStream can write to an array of bytes. Saving to a file would be very slow in performance, and not necessary in this case.
Cheers
|
|
|
|
|
Thanks Jeff
Smitha
Imagination is more important than knowledge.
--Albert Einstein
|
|
|
|
|
Hi all expert:
do u have any idea on how to capture image (from media player video)?
so later i could edit it as normal image?
alternatively, it would also be good if i can directly drawing graphics on the particular frame of the video.
which way could be possible and how can I achieve that?
very appreciate for your help.
|
|
|
|
|
can you embed a wav inside a resouce file somehow ? also is it possible to PInvoke the "error" sound that accompanies a MessageBox with the MessageBoxIcon.Error property set ?
Jesse M
The Code Project Is Your Friend...
|
|
|
|
|
jtmtv18 wrote:
can you embed a wav inside a resouce file somehow ? also is it possible to PInvoke the "error" sound that accompanies a MessageBox with the MessageBoxIcon.Error property set ?
The embedding is easy, just add the wav to your project and set it embedded content, the use Assembly.GetManufestResourceStream("namespace.filename.ext") to get a stream object from this.
Playing it. The is a nice article of CP that shows you how to play wave file with P/Invoke. Let me know if you need help loading from memory.
Cheers
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
i do need help setting up the memory stream. i use directx 9.0 to play it; ie
private void PlayAudio(string fPath){<br />
Audio player = new Audio(fPath);<br />
player.Start();<br />
}
if the audio file is coming from a memory stream how do i get the bytes to stream to the above method ? thanks leppie. ps.. the audio file will be named Error.wav;
just reading the overload methods for Microsoft.DirectX.AudioVideoPlayback.Audio i find that it only takes a (strin filename) ..how can i tell it to play my embed resource instead? (which will come in a stream)
The Code Project Is Your Friend...
|
|
|
|
|
jtmtv18 wrote:
directx 9.0
Thats a bit over the top , dont you think?, use p/invoke rather
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
Aeru IRC project is looking for developpers and artists.
Aeru IRC is free and open source IRC Client for .NET.
Unlike most of others .NET IRC Client, I don't use a external IRC library, it's my own IRC implentation.
You can find the client at http://aeruirc.sourceforge.net/
I need developpers who can contribute their coding talent to fix bug, refactoring somes parts and adds features. I work with Windows.Forms and Magic Library(soon UtilityLibrary for the toolbar).
Also, I need artist to draw the menu icons, tab icons. In future, I will neeed an artist to doing toolbar images(I waiting for a artist to implent this feature).
If you are interested, email me at shock@shockdev.ca.tc.
Thanks in advance!
-Shock The Dark Mage
Aeru IRC programmer and project maintener.
Trully, if there evil in this world, It lies within the heard of mankind
Shock The Dark Mage
shock@romhack.net
Main Project: Aeru IRC - http://www.sf.net/projects/aeruirc
|
|
|
|
|