|
Thanks Mike!
I have seen...
It was a very silly bug...
*rrrhhh - Sometimes I am so stupid*
Thank you very very very much for your help on my stupid questions...
I hope I can invite you to one or some more beer when I will travel to Los Angeles anytime in the next years!
Daniel
---------------------------
Never change a running system!
|
|
|
|
|
I am trying to capture a bitmap or an icon from a .bmp or .ico file selected by a user from a standard CFileDialog dialog.
LoadImage() always fails (returns 0 and hBitmap or hIcon are NULL).
CString strAppPath;<br />
CSString strImagesDirectory;<br />
CString pathName;<br />
CString fileName;<br />
CString extName;<br />
HICON hIcon;<br />
HBITMAP hBitmap;<br />
<br />
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, "Bitmap(*.BMP)|*.BMP|Icon(*.ico) <br />
*.ico||", this);<br />
if( dlg.DoModal() == IDOK )<br />
{<br />
pathName = dlg.GetPathName();<br />
fileName = dlg.GetFileTitle();<br />
extName = dlg.GetFileExt();<br />
<br />
if (extName == "ico" || extName == "ICO")<br />
{ <br />
hIcon = (HICON)::LoadImage( NULL, pathName, IMAGE_ICON, 0, 0, <br />
LR_LOADFROMFILE|LR_DEFAULTCOLOR ); <br />
if (hIcon)<br />
SetIcon(hIcon, TRUE);<br />
}<br />
else<br />
{<br />
hBitmap = (HBITMAP)::LoadImage( NULL, "C:\\HAPPY.BMP", IMAGE_BITMAP, 0, 0, <br />
LR_LOADFROMFILE|LR_CREATEDIBSECTION);<br />
if (hBitmap)<br />
bmpImage->Attach(hBitmap);<br />
}<br />
<br />
}
I have tried a number of things with the second parameter of the LoadImage() call -- hard coded path to the file, path as captured by the CFileDialog, image files in the root directory and located in a variety of other locations (including the directory of the working project). Nothing works. I have searched the documentation and what I have should work.
I am working on Windows 2000 Professional and in Visual Studio .NET but in unmanaged C++ code.
Anyone have any idea whta I am doing wrong?
Sydney Liles
Software Engineer
|
|
|
|
|
The first parameter should be the instance of your module. Passing NULL instead is only for OEM images.
How low can you go ? (MS rant)
|
|
|
|
|
This is one of the things I have tried. I tried it again after I got your response. No luck.
I changed the code to look like this:
CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY, "Bitmap(*.BMP)|*.BMP|Icon(*.ico)<br />
|*.ico||", this);<br />
if( dlg.DoModal() == IDOK )<br />
{<br />
pathName = dlg.GetPathName();<br />
BYTE FileBuffer[10240] = "";<br />
fileName = dlg.GetFileTitle();<br />
extName = dlg.GetFileExt();<br />
<br />
HINSTANCE hInst = AfxGetInstanceHandle();<br />
<br />
if (extName == "ico" || extName == "ICO")<br />
{ <br />
hIcon = (HICON)::LoadImage(hInst, pathName, IMAGE_ICON, 0, 0, <br />
LR_LOADFROMFILE|LR_DEFAULTCOLOR); <br />
if (hIcon)<br />
SetIcon(hIcon, TRUE);<br />
}<br />
else<br />
{<br />
hBitmap=(HBITMAP)::LoadImage(hInst, "C:\\HAPPY.BMP", IMAGE_BITMAP, 0, 0, <br />
LR_LOADFROMFILE|LR_CREATEDIBSECTION);<br />
if (hBitmap)<br />
bmpImage->Attach(hBitmap);<br />
}<br />
<br />
}
I know I am getting a valid HINSTANCE.
Any other suggestions?
BTW -- I really do appreciate the help.
Sydney Liles
Software Engineer
|
|
|
|
|
Code from MSDN[^].
How low can you go ? (MS rant)
|
|
|
|
|
Boy, I sound like my children (no, that won't work)
I did try that -- This is one of the documents I found that discusses LoadImage(). The problem remains the same. When I add this code to my own, then the LoadImage() call in the LoadBitmapFromBMPFile() fails.
BOOL LoadBitmapFromBMPFile( LPTSTR szFileName, HBITMAP *phBitmap,<br />
HPALETTE *phPalette )<br />
{<br />
<br />
BITMAP bm;<br />
<br />
*phBitmap = NULL;<br />
*phPalette = NULL;<br />
<br />
<big>*phBitmap = (HBITMAP)LoadImage( NULL, szFileName, IMAGE_BITMAP, 0, 0,<br />
LR_CREATEDIBSECTION | LR_DEFAULTSIZE | LR_LOADFROMFILE );</big> <br />
if( *phBitmap == NULL )<br />
return FALSE;<br />
I think there is something going on with LoadImage() itself. I thought that the .bmp files I was using to test might be the problem because they are very old and have not been updated. I got a .bmp with lots more information stored in the properties and it does not work either.
The only thing I can think of is that LoadImage() fails on Win2K. I read a Microsoft Knowledge Base article to this effect http://support.microsoft.com/default.aspx?scid=kb;en-us;Q329092. I do not have access to a Win9x machine with Visual Studio installed to test this theory.
Thanks though.
Sydney Liles
Software Engineer
|
|
|
|
|
What does GetLastError return after you call this function and it fails?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
Funny you should ask.
I just added a call to GetLastError() a few minutes ago and realized that I had created a CFile (to get size information), opened it, read the contents of the .bmp into a buffer(in an attempt to get LoadImage() to work) and then closed it after I attempted to call LoadImage() -- GetLastError() returned 32 (ERROR_SHARING_VIOLATION). I moved the CFile::Close() to before the call to LoadImage() and now all is well.
It was a dumb thing to over look. Wish I had tried the GetLastError() sooner. Oh well.
Thanks for all of the help.
Sydney Liles
Software Engineer
|
|
|
|
|
Hi
the last few weeks I modified some files in my Platform-SDK directory, resulting in linker errors and missing files
Now I have uninstalled the latest Platform SDK completely and reinstalled it again, but I still keep getting this error (German):
C:\PROGRAMME\MICROSOFT SDK\LIB\LIBC.lib : fatal error LNK1112: Computer-Typ "IA64" fuer Modul steht in Konflikt mit dem Ziel-Computer-Typ "IX86"
This seems to me to be a conflict between 32bit and 64bit libraries. My project is build for 32bit platforms.
But the first library path the compiler should use is defined as C:\PROGRAMME\MICROSOFT SDK\LIB\ , that's why I don't know how the error can occur.
thanks in advance
Greg
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Try to find this path in the registry, and modify it or kill it.
How low can you go ? (MS rant)
|
|
|
|
|
I did both, but nothing helped
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hello,
I want to ask how to store a String in 2-D array foramt?
e.g.
abc[0][0]="A";
abc[0][1]="AA";
abc[0][2]="AAA";
......
....
..
abc[n][n]="AAAAAAAAAAAAAAA";
THX!!!
I am not using MFC, just the console mode!!!
I think it for a long time!!!
|
|
|
|
|
If your 2-D array will simply hold literal strings, like in your example, declare it as a 2-D array of pointers to characters, like this:
char* abc[N][N];
This assumes N is a predefined constant value.
Regards,
Alvaro
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
|
|
|
|
|
I am developing for a Windows CE device in which there is a bug where files that are divisble by 2048 aren't copiable from the permanent storage to the volatile storage. At this moment I have been just checking to see if the exe's and dll's are divisible by 2048 and if so add some characters to the end of the file. Is this a safe practice or should I be doing something else.
I have tried putting an int padding[] = {0, 1,..., etc} in the file but it seems the file doesn't change in size; which, I could only assume is the optimizing compiler removing it.
Cheers,
Clint
|
|
|
|
|
I'm sure that there is a linker setting for this, but I can't remember it at all...
And, for the padding, for the compiler optimizer do not remove it, try do something, like reading all the array in a for loop...
Q261186 - Computer Randomly Plays Classical Music
|
|
|
|
|
I was trying to get Googles webpage by using Winsock. But the real problem is I am behind Firewall (Microsoft ISA). As far as the Winsock is concerned getting webpage within the Firewalll is not difficult. But when I try to access behind the Firewall the Server won't allow me anymore.
Please anyone can help regarding how can I access a webserver behind firewall by using Winsock. How can I use or implement Proxy support in my program.
Dammy More
|
|
|
|
|
You should check out the relavent RFC on supporting a HTTP Proxy. For an example of winsock programming which works thro a HTTP proxy, check out my CDDB class at http://www.naughter.com/mfccddb.html
|
|
|
|
|
hi
it's my third time posting this question in as many days! I wrote my own wave file, but when i want to play it with sndPlaySound, i only get a beep from the PC speaker. Other applications play the file fine, and other wave files are played with the sndPlaySound function in my app.
WHAT'S WRONG?
PLEASE!!
|
|
|
|
|
Send me the file and the snippet of code that plays it.
|
|
|
|
|
Is there a system type command in MFC? Or do I have to use system to launch another application from within my application?
Thanks
ashish
|
|
|
|
|
Try ShellExecute
I am seeking...
For what?
Why did you ask me for what? I don't know!
|
|
|
|
|
CreateProcess, WinExec, ShellExecute or ShellExecuteEx spring to mind. All documented in the MSDN
|
|
|
|
|
Nice to see you on the VC++ forum, PJN!
/ravi
Let's put "civil" back in "civilization"
http://www.ravib.com
ravib@ravib.com
|
|
|
|
|
|
Admittedly I know less about threads then I thought I did about an hour ago. I had thought that threads allow for a process to be completed at the same time code execution is continuing past the creation of the thread. Is this a correct way to look at them (threads) and if so, is there a way to hold the program until the completion of the last created thread?
---------------------------------------------
Be good! But if you can't be good, at least be good at it and try not to get any on ya!
-mjf
|
|
|
|