|
I have a class (MyComponent) that is derived from WebService. When ever I derive another class from this one the window that you switch to code view from puts up a message saying that the type initalizer for MyComponent threw an exception. What does this mean and how do i fix it?
Thanks.
Steve
Not all who wander are lost...
|
|
|
|
|
My latest place that I'm stuck...
I call a function using DllImport that returns a pointer to some memory. How do I now write it to a file? The Write method doesn't take a pointer.
Thanks guys!
----------------------------------------------------------------
IntPtr pOutputBuffer = IntPtr.Zero;
IntPtr pInputBuffer = bmData.Scan0;
int iResult = wsq_compress_raw( pInputBuffer, ..., ref pOutputBuffer, ... );
FileStream pStream = new FileStream( strPathName, FileMode.Create, FileAccess.Write );
BinaryWriter pWriter = new BinaryWriter( pStream );
pWriter.Write( pOutputBuffer, 0, iCompressFileSize ); // Error
pWriter.Close( );
pStream.Close( );
|
|
|
|
|
This should probably work:
unsafe
{
pWriter.Write((byte*)pOutputBuffer.ToPointer(),0,iCompressFileSize);
}
|
|
|
|
|
Thanks! I was headed there a few times, but...
unsafe
{
pWriter.Write((byte*)pOutputBuffer.ToPointer(),0,iCompressFileSize);
}
Gives the error: cannot convert from a byte* to byte[]
unsafe
{
pWriter.Write((byte[])pOutputBuffer.ToPointer(),0,iCompressFileSize);
}
Gives the error: cannot convert type void* to byte[]
|
|
|
|
|
I'm sorry I have to keep stabbing in the dark but offhand I can't recreate an example to test. So here's the next attempt:
Marshal To the Rescue!!! (System.Runtime.InteropServices.Marshal)
byte[] ba = new byte[iCompressFileSize];
Marshal.Copy(pOutputBuffer,ba,0,iCompressFileSize);
pWriter.Write(ba,0,iCompressFileSize);
|
|
|
|
|
Perfect!!! Nice job and thanks!
|
|
|
|
|
No Prob. I must say I am a little dissapointed in this solution though. Having to allocate and copy the data through another byte[] will slow down your app, especially if this is a non-trivial file you're trying to write.
I'm certain there has to be a way to marshal a memory location as a standard byte[]. After all, its perfectly legal to do this:
byte[] ba = new byte[100];
byte* pb = ba;
*pb = 1;
|
|
|
|
|
I totally agree with you. The memory is already out there, all I need is a byte pointer to it.
But with the bounds checking in place, I don't see a good way of doing it.
|
|
|
|
|
I can't think of any good way to do it, either.
It's trivial in C# to get a pointer to a managed piece of data as long as you fix the managed object, but in this case, you've got a pointer to an unmanaged piece of data.
|
|
|
|
|
hi there,
i want my app to appear in different languages. the user may choose his prefered language in an options-dialog.
which way would YOU do that?
* define a seperate class, containung a string-member for each string-constant?
* some resource-thing (as it was with the string-tables in C++/MFC-times)
* is there something built-in in C# for that purpose?
* ...
what about the language-files (containing all the strings)? is xml overkill?
i'm currently in the phase of thinking about it, implementing comes later. my current favorite is as described - a class containing a string-member for each message initialized by an xml-file for each language. so when the user changes the language, the class just reads a different xml-file, rewrites all of its string-members and everything is redrawn/reassigned. but i'm not sure, if this is the best way...
so if anyone has some hints, i would be glad to read them...
:wq
|
|
|
|
|
Have you seen the 'Language' property?
Go to your dialog, change the 'Language' to the desired locale, and then .NET handles it for you. Was one of the neatest features I've seen in the IDE yet.
|
|
|
|
|
what's the use? it didn't changed anything (i thought at least the system-menu-entries (minimize, maximize, move, etc.) should have changed)
btw: this doesn't help with the menu and labels etc. because I assign the text-properties myself (or is there some hidden dictionary somewhere) - and when i want my application to appear in a completely different language, all texts have to be changed.
or am i getting something wrong...
:wq
|
|
|
|
|
No, it doesn't change anything. You need to change it.
Make a new dialog and put the text field 'Name:'
Now change the language to French and rename the field 'Nom:'
Now change the language back to English.
Cool, eh?
|
|
|
|
|
I would choose build-in function called globalization.
In the property window there is a property called Language.
First of all, enter text for your controls in the default language. Then change the language to another and change text.
For one language the editor creates one .resx file the WinForms directory.
For example:
default language - MainForm.resx
second language (in this case Polish) - MainForm.pl.resx
For details see the documentation
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
I almost forget.
The following code shows how to change the language programmatically
System.Globalization.CultureInfo culture =
new System.Globalization.CultureInfo( "fr" );
System.Threading.Thread.CurrentThread.CurrentUICulture = culture;
where fr is a language code ( see MSDN ).
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
i just want to mention, that using the form-editor was a BAD idea.
my menuitems are objects of my own menuitem-class - after just changing the language in the properties-window, the menu completely vanished. setting the language back to 'default' didn't bring it back! the variables are still there, but the AddRange-functions of the main menu items were absent. ok, i added them by hand. fault! the form-designer showed me an error-message instead of the form-preview.
i corrected these things by changing the order of the variable-definitions (!!!) - but the designer now doesn't work, as he did before. the additional properties of my menuitems are set back each time i compile after using the form-designer...
i tell you: you better stick to the standards when using the form-designer.
i will do that all by hand from now on...
:wq
|
|
|
|
|
The globalization function is cool.
The C# designer seems not to work correctly with custom classes, for example Menu.
I use globalization but I don't use designer. I write my own code.
This code use Carlos H. Perez's library - designer is not supported.
There is only one minus of it. You must create the resources yourself using resgen.exe and al.exe
private System.Resources.ResourceManager m_mResources = new System.Resources.ResourceManager(typeof(MainForm));
ToolBarEx menuToolBar = new ToolBarEx( BarType.MenuBar );
ToolBarItem menuFile = new ToolBarItem( (string)(m_mResources.GetObject("Menu.File")) );
MenuItem[] submenuFile = new MenuItem[3];
submenuFile[0] = new MenuItemEx( (string)(m_mResources.GetObject(
"Menu.File.Options")), new EventHandler( OptionsHandler ), Shortcut.CtrlO );
submenuFile[1] = new MenuItemEx( "-", null );
submenuFile[2] = new MenuItemEx( (string)(m_mResources.GetObject(
"Menu.File.Close")), new EventHandler( CloseHandler ) );
menuFile.MenuItems = submenuFile;
43 68 65 65 72 73 2c
4d 69 63 68 61 65 6c
|
|
|
|
|
I can not close the window with X on the window(System close)
Can anyone help me with that?
Thanks
|
|
|
|
|
what functions did you overwrite in your application?
:wq
|
|
|
|
|
I did not over write any function?
|
|
|
|
|
in the case, it doesn't close when you click - does it close when you click a second time?
maybe it's a focus-problem (although windows are closed when you click the "x" and they don't have the focus...)
:wq
|
|
|
|
|
I can not close at all.
but If I create a Exit menu and put "Dispose(true);" then I can close the window.
X is not calling the Dispose(true) methode at all.
Thasnks
|
|
|
|
|
If you want to build a COM server component using Visual C#, which project type do you choose in the "New project" window?
|
|
|
|
|
Anything will do. You can use EXE or a DLL. You need to apply the correct attributes and register the assembly using regasm
|
|
|
|
|
May be I am stupid, But what are you talking about.
Sometime I can close my main window and some time I can not close the window with system menu. Are you talking about this?
Thanks
|
|
|
|