|
Mihnea Radulescu wrote: the latest Mono version is considered to be 100% compatible with the corresponding MS implementation
Ha ha ha ha ha ha....
I've not tried it for winforms, but did fairly extensively for ASP.NET, and found the compatibility to be well under 100% - maybe 95% at best. Unfortunately, it's the little bits that either don't work at all or are slightly different enough to crap your app out - understandable as it's not a paid development, and the coders have presumably got it working enough to support their code then said "That'll do".
Create a new project.
Import a bit of your existing code.
Test it under windows.
Test it again under mono.
Fix the broken bits.
Repeat.
Import a bit more code.
et., etc.
Good luck!
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Hello everyone,
I am trying to use some managed code with some unmanaged rendering functions using OpenGL. I have a C# bitmap and I am trying to use OpenGL functions to draw on this bitmap.
Currently, my problem is that I am unable to initialize OpenGL and it fails with the error "Attempted to read or write protected memory. This is often an indication that the other memory is corrupt".
My OpenGL initialization routine is as follows (this is implemented as a C++ DLL function):
extern "C" __declspec(dllexport) BOOL InitGL(HDC * hdc,
HGLRC * hglrc)
{
BOOL retval = FALSE;
PIXELFORMATDESCRIPTOR pfd;
int format;
ZeroMemory(&pfd, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_BITMAP | PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
format = ChoosePixelFormat(*hdc, &pfd );
retval = SetPixelFormat(*hdc, format, &pfd);
*hglrc = wglCreateContext(*hdc);
return retval;
}
The important bit here is the use of PFD_DRAW_TO_BITMAP and PFD_SUPPORT_GDI. I have tried drawing directly to window (using PFD_DRAW_TO_WINDOW) and that works ok.
It is called from C# as follows (I am omitting the DLLImport sections here and just focussing on the call).
Additionally, _bitmap is the bitmap object that I want to draw on.
try
{
Graphics graphics = System.Drawing.Graphics.FromImage(_bitmap);
IntPtr hDC = graphics.GetHdc();
if (!native_init)
{
NativeMethods.InitGL(hDC, out this._hglrc);
native_init = true;
}
}
finally
{
}
I thought that maybe I need to lock the bitmap data and I tried the following:
try
{
BitmapData bitmapData = _bitmap.LockBits(
new Rectangle(0, 0, _bitmap.Width, _bitmap.Height),
ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
Graphics graphics = System.Drawing.Graphics.FromImage(_bitmap);
IntPtr hDC = graphics.GetHdc();
if (!native_init)
{
NativeMethods.InitGL(hDC, out this._hglrc);
native_init = true;
}
}
finally
{
_bitmap.UnlockBits(bitmapData);
}
However, this fails with the same error. I am not sure how I can use this locked bitmap data to initialize the OpenGL context.
Any help here would be really appreciated. I have spend hours looking at this and trolling the net to no avail now!
Thanks,
Keith
|
|
|
|
|
Ok, I fixed that problem. So, there were two issues:
First, I had to call ReleaseHdc on the graphic object.
Secondly, the HDC parameter should have been declated as an 'out' parameter.
However, there is another problem. However, this is more related to OpenGL and probably not suitabvle for this forum.
Thanks,
Keith
|
|
|
|
|
I have been studying C# for 6 months now. Perhaps I should have but I haven't yet run into the use of var for implicit variables and - in the following example - the subsequent replacing of parentheses with braces for enclosing the parameters.
var viewModel = new StoreIndexViewModel {
NumberOfGenres = genres.Count(),
Genres = genres};
I assume there is a particular reason for this? Any help would be appreciated. Thanks.
Darrall
|
|
|
|
|
This feature of C# is known as "Object Initializers".
Read about it here or on msdn.
|
|
|
|
|
Thanks
|
|
|
|
|
You can make the code more readable (though that's subjective).
E.g
var x = new Dictionary<string, List<person>>();
instead of
Dictionary<string, List<person>> x = new Dictionary<string, List<person>>();
You can use them in LINQ queries where the result type is not obvious - the compiler will get it right. You can find out the type by hovering over the var in VS - it may not be what you think. Worth experimenting with.
This is one of those topics that cause 'religious' debates or flame wars - though that seems to have died down. Some people say 'Never' others 'Always'.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
Thanks...that makes sense
|
|
|
|
|
Hi there
Does anybody know if System.Globalization can produce a list of states/provinces for a given Country?
|
|
|
|
|
AFAIK, it cannot. One can get the list of countries from the registry entry for telephony but states, I guess no.
|
|
|
|
|
The CultureInfo class contains country and language information, but no state / province level information.
|
|
|
|
|
No it can't. That's not what it's designed to do. This type of information has to be coded/collected yourself I'm afraid (although there are purveyors of geographic database libraries out there who've done the hard work for you already).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi there
I understand I can create a list of countries in a combobox using System.Globalization.
I haven't been able to figure out how to do it.
Anybody know how?
|
|
|
|
|
public static List<string> GetCountryList()
{
List<string> cultureList = new List<string>();
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
foreach (CultureInfo culture in cultures)
{
RegionInfo region = new RegionInfo(culture.LCID);
if (!(cultureList.Contains(region.EnglishName)))
cultureList.Add(region.EnglishName);
}
return cultureList;
} Then just add the list to the combobox
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Wow. I had no idea .NET held a list of countries like that.
And grrrr, they had to use the French "NativeName" for Belgium. So why don't they show the US in Spanish?
In fact they do, if we look at all the cultures, including EnglishName duplicates.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
modified on Sunday, May 16, 2010 2:59 PM
|
|
|
|
|
It's nice to know it's not just me who keeps on finding new things in .NET!
I have learnt that you can not make someone love you, all you can do is stalk them and hope they panic and give in.
Apathy Error: Don't bother striking any key.
|
|
|
|
|
Hi ,
I need to create a code number automatically for the name entered. If the name is already used then add a number at it's end like 1 or 2 depending upon the highest value available in the database.
something like namexx where xx is the highest number plus 1.
please help it's very urgent.
|
|
|
|
|
And what have you tried? Or since it's very urgent you expect someone to write it for you?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
i tried to put the string of the latest code in an array and parse it for int.
put the integers in a integer array. then convert them to form a string of int values and add 1 to this string converted to int.
but i couldn't split the initial string!!! what should be the split criteria?
string would be always of form
fname.lnamexxx where x could be any number 1, 99,999,9999 anything.
don't need anyone to write a code just an immediate help, if possible for split criteria of the initial string[fname.lnamexx] .
|
|
|
|
|
You don't need to parse the ints or use an array.
Assuming the names are in a datatable, something like this
int x = 1;
string name =
while(datatable.select('name = ' + name).count() != 0)
{
name = name + (x++);
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
oh..uh.. ..this is cool
Y did i not think this...grr
Thanks, Mark
|
|
|
|
|
OH.. this will not work if the code is deleted in between then the count and max number at end will be an issue
|
|
|
|
|
I have no idea what you are talking about.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Why don't you just have a identity column in your table. At that point, how many instances of a name (or any column value for that matter) you have is inconsequential...
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
so, add a table "known_names" to the database, two fields: name, occurence_count (do not try to reuse an existing table holding actual people!).
when adding a new name, check "known_names" for existence;
if it isn't there, add it with occurence_count=0, and use codedName=name
if it is there, increment its occurence_count, and use codedName=name+occurente_count.ToString()
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|