|
|
Well, he did answer your question.
Converting anything to anything is done using decoders and encoders. Microsoft DirectX does a great job of this and has a managed API for use with .NET. You can find more information about Managed DirectX 9.0b and download the DirectX runtime and managed components from http://msdn.microsoft.com/directx[^].
You chain a decoder for the MPEG (which, keep in mind, there are different codecs for MPEG) to an encoder for an AVI (again, there are many types of encoders and, in fact, AVI does not define a particular codec for either sound (if applicable) or video).
So, to provide you with any examples, it really helps to know exactly what you want to do, because there are so many ways of doing this. Besides, do you really need to write a program to do this? There are tons of free applications on the 'net that already do this, and even the DirectX SDK includes a utility (GraphEdit) that lets you link decoders and encoders (as well as DMOs and other handy utility classes) and do whatever you want (with what's installed on your system).
There are other ways to do this as well, and unless you find a simple unmanaged library that lets you do this with one or two function calls (which you can P/Invoke in C#), they won't be easy to use. .NET is just too high-level to do stuff like this easily (unless you were to write a mixed-mode Managed C++ project that calls native functionality from a managed execution environment which can be used by any other managed language projects, like those in C# and VB.NET).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello, I'm writing a small application in which a draw onto a panel and want to control the painting on the panel with the arrow keys (think of it as a painting program with the keys instead of mouse if you wish..)
Now the thing is, from what I figure the Panel can't gain keyboard focus. So I would need some other way to retrieve the key events. What do I do? Place a dummy control somewher, hide it, give it keyb. focus and then reacts on the events from there?
A better solution? If so please tell me the 'right' way to do it..
/Bjorn
|
|
|
|
|
Is it possible for you to use a UserControl rather than a panel? That would solve your keyboard input problem.
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|
Yes it's most certainly possible, thanks for the suggestion. But just out of interest, would there be a way to do it even with a panel control? And if so, how?
|
|
|
|
|
The only thing I can think of is to have the form that the panel is on receive the keyboard events. Then it could call functions that cause your panel to do appropriate things.
Karl Baum
CEO of KGB Technologies
Specializing in custom software development.
|
|
|
|
|
Hi Guys...
My Name Is Hani And I'm a New Member 2 Code Project..
I'm Planing 2 Develop A Buetooth Application On My PC Wich Can Allocate All The BT Devices Around, Send & Receive text msgs From Them & Catch This txt msg To Work On It.!!
Do Any 1 Knows How To Deal With My (MSI BT USB) connected To My PC In My Code(C#.net Or VB.net)..?
I Need 2 Know How To Start..!
Is There Any SDK To Use..? IF Yes, Where Can I Get It..?
Please Any Pice Of Clear Code And Steps Will Be Helpfull..!!
Thx 4 Listening And I'm Waiting 2 Hear From You ASAP.
Thx Again
Regards 2 u All.. )
|
|
|
|
|
A five second search on MSDN for "bluetooth" netted:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/bluetooth/bluetooth/about_bluetooth.asp
|
|
|
|
|
Posting you messages in multiple forums at the same time is considered very rude, so please don't.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i want to implement a personal firewall
with packet filtering api's but i dont want
to just filtering packets iwant do some more
works like other firewalls
1-i want to notify the user when
a program try to access to internet do you think
is there any event in .net or in windows for this
purpose and if there is which events
2- i want to see all open ports in mycompuetr
somthing like netstat command in windows but iwant
do this programmatically
3-if i saw a port is open how can i close it
programmatically
koosha
|
|
|
|
|
|
Most, if not all, firewall programs work by using an NDIS Hook to (in simplified terms) see all the packets fly through the network adapter. They get a chance to examine every packet that passes through and can optionally pass the packet to the network adapter (on the way out) or pass it on to Windows (on the way in). A firewall works by just dropping any packet it doesn't like the look of.
In answer to #3. If you want to close a port then all you need to do in your NDIS Hooked code is to block any packets on that port. As you examine every packet as is passed through, this means that you just don't pass the packed on the ports you want closed.
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
The Second EuroCPian Event will be in Brussels on the 4th of September
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
My Blog
|
|
|
|
|
Really i thought that using the hook would wind up degrading performance, and that a seperate socket layer was used. Interesting thanks
Discovery consist of seeing what everybody has seen and thinking what nobody has thought -- Albert Szent-Györgyi
Name the greatest of all the inventors: accident --Mark Twain
|
|
|
|
|
I've created a user control and added a designer for it so I can add some custom code that will setup the form to work with the control. Problem is, I have keep track of the number of these controls that have been created. Reason is that I need to display them in a certain order. So, let my control be called jControl... then I need to generate something like the following: jControlsCollection.Add(jControlk.layered ? jControlk.layer : k); This way, I can draw the jControls in the order that they are created in the designer if I want, or set some layer that they should appear on. I have the code to put the code into the forms document, but don't have a way to get k(the kth control that I just created in the designer).
Also, while debugging my designer, I've noticed that: public override object Serialize(IDesignerSerializationManager manager, object value); gets called just about any time some happens to the control... even when the control is deleted... so I need a way to tell what happend to the control(like when it was first constructed(maybe by using a constructor, not sure... I don't know much about what I'm doing... just what I want to do ;/). I can't seem to find much information on it, and the info that is doesn't go into much detail about what I want to do.
Anways, any help would be appreciated! Thanks, JS
P.S. How can I generate code for the controls only once. Basically, I would like to setup my form to use the controls(declare a jControlsCollection and add the controls to it). i.e. generate the code for only once and only if there is atleast one jControl on the form).
|
|
|
|
|
The fact of the matter is that you can't control how the designer does things, only how it interacts with your code. In fact, in many of the more well-written topics in the .NET Framework SDK covering design-time functionality, this is basically stated.
Serialize is called on any container being designed (if applicable) when anything happens because the source code must be kept in-sync.
The fortunate thing is that controls are instantiated as they would be at runtime by the designer. If you want to keep track of information about a control (such as how many are created), then add a static field (probably a private static field) and increment that in your constructor. You can also decrement that in the finalizer (written in descructor notation as ~<classname()> ) or implement IDisposable , which the designer should call when done with your object (you can never be gauranteed of when the finalizer is called by the GC).
Still, though, a collection (ICollection implementation, presumably) has a Count property. The kth element is Count - 1 . Why can't you use that for whatever you're doing? And the order of the controls if the order in which they were added (unless you inserted a control before the end of the collection, of course).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
well, I tried to messa round with that stuff and doesn't seem to work(For me atleast, I just started recoding after a couple of years and I'm not up to par at the moment). I've tried that static method and problem is, constructor is called even when deleted the control. I've tried the IDisposable, but not sure how it works(seems to not be called all the time or sometimes to many times(used code reference from .NET sdk). The only thing that seems to be consistant is that the serializer gets called each time and for all controls when one is added or deleted to the form design(so, when I add the 4th control, it will call serializer 4 times). I got all this through debugging.
Heres what I need to do(create designer to generate):
// Is created only when one or more jControl's exist
// Is deleted when there are no jControl's
jControlsCollection jControls = new jControlsCollection();
//
// jControlk
//
// The next lines are generated by the base serializer
this.jControlk = new ns_jControl.jControl();
this.jControlk.Location = new System.Drawing.Point(56, 32);
this.jControlk.Name = "jControl1";
this.jControlk.Size = new System.Drawing.Size(112, 96);
this.jControlk.TabIndex = 0;
// I want to add this line
// the problem being, how do I figure how what k is in my code generator
// Only way I can think of is by extracting it from one of the previous code statements
// But that seems like a hack to me, and theres gotta be a better way...
this.jControls.Add(this.jControlk)
P.S. I know it can be done because the default code generator does it. It adds "this.SuspendLayout();" only once.
|
|
|
|
|
this.SuspendLayout is for the Form or UserControl itself (hence, this ). But your code is added only once, too. Just because Serialize is called more than once at design-time doesn't mean your serialized code is repeated over and over again - just look at the source. As I said before, this is how the designer keeps in sync with the source code. How else could it be done?
I gave you a link to an article that gives a good example. You can also use DesignerSerializationVisibilityAttribute with DesignerSerializationVisibility.Content as the argument on the property which has hte collection of jControlk *. This tells the designer to serialize the contents of the collection to your source file, but it seems to work only for reference types (not value types, like structs, enums, and the primitives). If you need to do more advanced customization, then you need to implement a designer serializer. Again, there are many articles here on CodeProject, including the one I linked you before. You really should read these, as well as the class documentation for related classes.
Finally, you really should take a look at Naming Guidelines[^] in the .NET Framework SDK. If you plan on releasing this as a library, following these guidelines keeps your types consistently named with every other type, which is important for Rapid Application Development (RAD) and helps the developers using your product (and a pleased client is a paying client). Consistent naming is not required, but is highly recommended.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
|
Hi all,
I'm currently trying to use the SetupDiGetDeviceInterfaceDetail function of the Setupapi.dll.
But unfortunately I can't get it working.
Here's my definition of the function:
[StructLayout(LayoutKind.Sequential, Pack=1)]
public class SP_DEVICE_INTERFACE_DETAIL_DATA
{
public int cbSize;
public short DevicePath;
}
[DllImport("Setupapi.dll", SetLastError = true)]
public static extern Boolean
SetupDiGetDeviceInterfaceDetail(
IntPtr DeviceInfoSet,
ref SP_DEVICE_INTERFACE_DETAIL_DATA DeviceInterfaceData,
IntPtr DeviceInterfaceDetailData,
int DeviceInterfaceDetailDataSize,
out int RequiredSize,
IntPtr DeviceInfoData);
Here's the piece of code where I call the function:
public void WDMEnumeration()
{
StringBuilder DeviceName = new StringBuilder();
Guid guid = MEDIA_GUID;
IntPtr NewDeviceInfoSet;
Win32APIfunctions.SP_DEVINFO_DATA DeviceInfoData= new Win32APIfunctions.SP_DEVINFO_DATA();
NewDeviceInfoSet=Win32APIfunctions.SetupDiGetClassDevsA(ref guid, 0, IntPtr.Zero, DIGCF_PRESENT);
if( NewDeviceInfoSet.ToInt32() == -1 )
{
throw new System.ApplicationException("device information is unavailable!");
}
for(uint uiDeviceIndex=0; uiDeviceIndex<MAXCARDS; uiDeviceIndex++)
{
DeviceInfoData.cbSize = 28;
DeviceInfoData.DevInst=0;
DeviceInfoData.ClassGuid=System.Guid.Empty;
DeviceInfoData.Reserved=0;
bool bResult = Win32APIfunctions.SetupDiEnumDeviceInfo(NewDeviceInfoSet, uiDeviceIndex, DeviceInfoData);
if(bResult == false)
{
Win32APIfunctions.SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
throw new System.ApplicationException("no such device!");
}
DeviceName.Capacity=MAX_DEV_LEN;
bResult = Win32APIfunctions.SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet, DeviceInfoData, SPDRP_FRIENDLYNAME, 0,DeviceName, MAX_DEV_LEN, IntPtr.Zero);
if(bResult == false)
{
bResult = Win32APIfunctions.SetupDiGetDeviceRegistryPropertyA(NewDeviceInfoSet ,DeviceInfoData, SPDRP_DEVICEDESC, 0, DeviceName, MAX_DEV_LEN, IntPtr.Zero);
if(bResult == false)
{
Win32APIfunctions.SetupDiDestroyDeviceInfoList(NewDeviceInfoSet);
throw new System.ApplicationException("incorrect device name!");
}
}
int dummy = DeviceName.ToString().IndexOf("Cinergy");
if(dummy != -1)
{
Win32APIfunctions.SP_DEVICE_INTERFACE_DETAIL_DATA dummyData = new Win32APIfunctions.SP_DEVICE_INTERFACE_DETAIL_DATA();
dummyData.cbSize = Marshal.SizeOf(dummyData);
int iRequiredSize=0;
Win32APIfunctions.SetupDiGetDeviceInterfaceDetail(NewDeviceInfoSet, ref dummyData, IntPtr.Zero, iRequiredSize, out iRequiredSize, IntPtr.Zero);
int iLastError = Marshal.GetLastWin32Error();
}
}
}
iLastError is always 87, which means ERROR_INVALID_PARAMETER.
But what am I doing wrong?
Best Regards
Bernd
Edit: Is there a way to format the source code in these forums? [code][/code] doesn't seem to work.
|
|
|
|
|
Pain_Elemental wrote:
Is there a way to format the source code in these forums? [code][/code] doesn't seem to work.
Use <code></code> for inline code and <pre></pre> for block code (which is actually what you should use in your case).
First of all, I noticed a lot of problems with your marshaling and your declarations. A DWORD is actually a uint , but an int will work (though you should use MarshalAsAttribute to make sure it's marshaled correctly), and the second field of SP_DEVICE_INTERFACE_DETAIL_DATA is a TCHAR[] , which is actually a string using the right encoding. Whenever you see that T in a char array type in Win32 APIs, it means that the string is ANSI on Windows and Unicode on Windows NT (depend on the #defines, of course; but Windows doesn't natively support Unicode). The correct declaration of the two structs and the function are as follows:
[StructLayout(LayoutKind.Sequential)]
private struct SpDeviceInterfaceData
{
public uint cbSize;
public Guid InterfaceClassGuid;
public uint Flags;
public IntPtr Reserved;
public SpDeviceInterfaceData(uint cbSize, Guid InterfaceClassGuid,
uint Flags)
{
this.cbSize = cbSize;
this.InterfaceClassGuid = InterfaceClassGuid;
this.Flags = Flags;
this.Reserved = IntPtr.Zero;
}
}
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]
private struct SpDeviceInterfaceDetailData
{
public uint cbSize;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=1)]
public string DevicePath;
}
[StructLayout(LayoutKind.Sequential)]
private struct SpDevInfoData
{
public uint cbSize;
public Guid ClassGuid;
public uint DevInst;
public IntPtr Reserved;
}
[DllImport("setupapi.dll")]
private static extern bool SetupDiGetDeviceInterfaceDetail(
IntPtr DeviceInfoSet,
ref SpDeviceInterfaceData DeviceInterfaceData,
out SpDeviceInterfaceDetailData DeviceInterfaceDetailData,
uint DeviceInterfaceDetailDataSize,
out uint RequiredSize,
out SpDevInfoData DeviceInfoData); From here you should be able to make the right calls. The problem with not marshaling data correctly is that things get in the wrong place. Lets say you just assume that a string field is Unicode string (how strings are stored in .NET, actually) but it's actually an ANSI field because it's running on Windows. Only half the string will be read (depending on the API implementation, a single character might only be read since the second byte may be interpreted as NULL). Or many people make the mistake of thinking that an unmanaged LONG is a long in C# (an Int64 ). A LONG is only 32 bits. This pushes the stack and extra 4 bytes, and it's that stack that provides the data for which a function executes.
That is most likely the reason for that error your getting. The wrong data was being sent (as far as the function call was concerned) so it returns a "wrong params" error.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks!
I just copied my definition of the structs and function from an other message board, because I am not familiar with this PInvoke stuff.
|
|
|
|
|
Hi Guys
Anyone knows the event , when we click on the row header for selecting a row ? also which is the event when we drag a row for resizing it ?
Pls help , its urgent
bye
krishnadevan.
If u can Dream.. U can DO it
|
|
|
|
|
hi
how i access to controls of a project in another project in a solution with two projects?
|
|
|
|
|
You have to add a reference to your project, which can be found under the "Projects" tabpage in the "Add Reference" dialog.
www.troschuetz.de
|
|
|
|
|
thanks
but i want access to controls of second project in stratup project .startup project dont make dll file and cant add it to second project reference.
please help more.
|
|
|
|
|