|
I'm not completely sure what your asking as the message as it isn't really clear...
If looking to load a resource from your library and not the calling executable you can use the GetModuleHandle[^] API passing NULL as the module name, this will then return a handle to your library. You can then use the LoadResource[^] API as per usual.
Gavin Taylor
w: http://www.gavspace.com
|
|
|
|
|
May I ask you all how to make an item moves randomly in a board game pls?
|
|
|
|
|
use rand() to generate two random numbers and set the coordinates of the window using SetWindowPos() .
That's all buddy.
*Of course you will have to set a timer to change the position in a specified interval of time
Wishes.
Anshuman Dandekar
Dare to Dream,
Care to Achieve.............
|
|
|
|
|
Hello,
I am trying to understand recursion by using the following example.
<br />
#include <iostream><br />
#include <iomanip><br />
<br />
using namespace std;<br />
<br />
unsigned long factorial( unsigned long );
int main()<br />
{<br />
for ( int i = 0; i <= 4; i++ )<br />
{<br />
cout << "\n i = " << i << endl;<br />
cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl;<br />
}<br />
return 0;
<br />
}
unsigned long factorial( unsigned long number )<br />
{<br />
if ( number <= 1 ) <br />
{<br />
return 1;<br />
}<br />
else <br />
{<br />
cout << endl << "number = " << number << " factorial(number - 1) = " << factorial(number - 1) <br />
<< " number * factorial(number - 1) = " << number * factorial( number - 1 ) << endl; <br />
return number * factorial( number - 1 );<br />
}<br />
}
<br />
I do understand that when i = 0, the base case is true, therefore 1 is returned. 0! = 1
When i = 1, the base case is true and 1 is returned. 1! = 1
When i = 2, the base case is not true, so number * factorial( number - 1 ) is returned, which is 2 * factorial( 1 ). 2 * 1 = 2. 2 is returned. 2! = 2
At this point, I have a question. The next line says i = 3. Then it says number = 2. How does number become 2 if i = 3?
Thanks,
Eric
|
|
|
|
|
The recursive calls have to complete before the output can be sent to cout . So what you're seeing is the output from the deepest recursive call first.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hasn't the output already been sent to cout? The program already output 2! = 2 and i = 3.
At the point in the program where i = 3 is output, doesn't that signify the beginning of a new iteration?
Thanks,
Eric
|
|
|
|
|
OK, I still don't get it. I changed the code a little to make the invocations easier to see.
<br />
#include <iostream><br />
#include <iomanip><br />
using namespace std;<br />
<br />
unsigned long factorial( unsigned long );
int count = 0;<br />
<br />
int main()<br />
{ <br />
for ( int i = 0; i <= 2; i++ )<br />
{<br />
cout << "\n i = " << i << endl;<br />
cout << endl << setw( 2 ) << i << "! = " << factorial( i ) << endl;<br />
cout << endl << "--------------------------------------------" << endl;<br />
}<br />
return 0;
<br />
}
unsigned long factorial( unsigned long number )<br />
{ <br />
count++;<br />
cout << endl << "factorial was invoked for the " << count << " time "<br />
<< " number = " << number << endl;<br />
<br />
if ( number <= 1 ) <br />
{<br />
cout << endl << "number <= 1" << endl;<br />
return 1;<br />
}<br />
else <br />
{<br />
cout << endl << "number = " << number <br />
<< " factorial(number - 1) = " << factorial(number - 1) <br />
<< " " <br />
<< number << " * " << factorial( number - 1 ) << " = " <br />
<< number * factorial( number - 1 ) << endl; <br />
<br />
return number * factorial( number - 1 );<br />
}<br />
}
OUTPUT:
<br />
<br />
i = 0<br />
<br />
factorial was invoked for the 1 time number = 0<br />
<br />
number <= 1<br />
<br />
0! = 1<br />
<br />
--------------------------------------------<br />
<br />
i = 1<br />
<br />
factorial was invoked for the 2 time number = 1<br />
<br />
number <= 1<br />
<br />
1! = 1<br />
<br />
--------------------------------------------<br />
<br />
i = 2<br />
<br />
factorial was invoked for the 3 time number = 2<br />
<br />
factorial was invoked for the 4 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time number = 1<br />
<br />
number <= 1<br />
<br />
number = 2 factorial(number - 1) = 1 2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time number = 1<br />
<br />
number <= 1<br />
<br />
2! = 2<br />
<br />
--------------------------------------------<br />
Press any key to continue<br />
*/<br />
Please walk me through the following:
<br />
i = 2<br />
<br />
factorial was invoked for the 3 time number = 2<br />
<br />
factorial was invoked for the 4 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 5 time number = 1<br />
<br />
number <= 1<br />
<br />
factorial was invoked for the 6 time number = 1<br />
<br />
number <= 1<br />
<br />
number = 2 factorial(number - 1) = 1 2 * 1 = 2<br />
<br />
factorial was invoked for the 7 time number = 1<br />
<br />
number <= 1<br />
<br />
2! = 2<br />
Thanks!
|
|
|
|
|
It appears that you are calling factorial() three times within itself (one for the algorithm itself, and two for the cout statements). With all of those cout statements, that may be leading to the confusion.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
If you are trying to track the stages of recursion with the cout line then I suggest that you minimise your confusion by calling your recursive function just ONCE and storing the result to use in your cout line and to return, I think that this will you help dissect what is going on?
Good luck I´m sure it will just click and you will go "Ah!"
|
|
|
|
|
OK, thanks to all of the great feedback, I have a better understanding about recursion.
I am now attempting to apply it and I have come across a problem that I can't seem to pinpoint.
I have written the "eight queens" program, but for some reason, I get an infinite loop. I think my base case is ok. Can someone help me figure out what I am doing wrong here?
Thanks in advance,
Eric
<br />
#include <iostream><br />
<br />
using namespace std;<br />
<br />
<br />
const int BOARD_SIZE = 8;<br />
<br />
void fillBoard( int [], int, int );<br />
bool noConflict( int [], int, int );<br />
void printBoard( int [], int );<br />
<br />
<br />
int main()<br />
{<br />
int chessboard[ BOARD_SIZE ];
int column = 0; <br />
int count = 0;
<br />
fillBoard( chessboard, column, count );
<br />
return 0;
}
<br />
<br />
void fillBoard( int board[ BOARD_SIZE ], int c, int cnt )<br />
{<br />
for( int r = 0; r <= 7; r ++ )
{<br />
board[ c ] = r;
<br />
<br />
if( noConflict( board, r, c ) )
{<br />
if( c == 7 )
{<br />
printBoard( board, cnt);
}<br />
<br />
else <br />
{<br />
fillBoard( board, c + 1, cnt );
}<br />
}<br />
}<br />
}
<br />
<br />
bool noConflict( int board[ BOARD_SIZE ], int r, int c )<br />
{<br />
for( int col = c - 1; col >= 0; col-- )
{<br />
if( board[ col ] == r
|| board[ col ] == r + c - col
|| board[ col ] == r + col - c )
{<br />
return false;
}<br />
else<br />
{<br />
return true;
}<br />
}<br />
return true;
}
<br />
<br />
void printBoard( int board [ BOARD_SIZE ], int cnt )<br />
{<br />
cout << "Count = " << ++cnt << endl;
<br />
for( int r = 0; r <= 7; r++ )
{<br />
for( int c = 0; c <= 7; c++ )
{<br />
if( board[ c ] == r )
{ <br />
cout << "Q ";
}<br />
<br />
else<br />
{<br />
cout << "- ";
}<br />
}<br />
cout << endl;<br />
}<br />
cout << endl;<br />
}
<br />
|
|
|
|
|
Hello everyone,
I'm writing a simple class to handle FTP SEND of a file from a WinCE 4.2 box. I'm having some trouble with the FtpPutFile call. I've tried several FTP servers using a valid username & password and get the same error every time.
InternetOpen succeeds, InternetConnect succeeds, FtpPutFile returns FALSE, GetLastError returns 12018.
The error message 12018 is defined in WinInet.h as follows
#define ERROR_INTERNET_INCORRECT_HANDLE_TYPE 12018
The type of handle supplied is incorrect for this operation.
Any input is greatly appreciated!
<br />
void CWinInetTestDlg::OnPut() <br />
{<br />
DWORD err = 0;<br />
CString str;<br />
<br />
<br />
HINTERNET hInternet = 0;<br />
<br />
<br />
LPCTSTR agent = _T("FTP");<br />
DWORD dwAccessType = INTERNET_OPEN_TYPE_PRECONFIG;<br />
LPCTSTR proxy = 0;<br />
LPCTSTR bypass = 0;<br />
DWORD flags = 0;<br />
<br />
<br />
LPCTSTR server = _T("X.X.X.X");<br />
INTERNET_PORT port = INTERNET_DEFAULT_FTP_PORT;<br />
LPCTSTR user = _T("user_name");<br />
LPCTSTR pass = _T("password");<br />
DWORD service = INTERNET_SERVICE_FTP;<br />
DWORD context = 0;<br />
<br />
<br />
LPCTSTR szLocalFile = _T("\\TEST.TXT");<br />
LPCTSTR szRemoteFile = _T("\\TEST.TXT");<br />
<br />
<br />
<br />
hInternet = InternetOpen(agent, dwAccessType, proxy, bypass, flags);<br />
if (hInternet) {<br />
<br />
flags = 0;<br />
if (InternetConnect(<br />
hInternet, <br />
server, <br />
port, <br />
user, <br />
pass, <br />
service, <br />
flags, <br />
context)) {<br />
<br />
flags = INTERNET_FLAG_TRANSFER_BINARY;<br />
<br />
if ( FtpPutFile(<br />
hInternet, <br />
szLocalFile, <br />
szRemoteFile, <br />
flags, <br />
context) ) {<br />
<br />
MessageBox(<br />
_T("FtpPutFile Success!"), <br />
_T("WinInet FTP Test"),<br />
MB_OK);<br />
<br />
}else{<br />
err = GetLastError();<br />
str.Format(_T("FtpPutFile Error: %d"), err);<br />
MessageBox(str, _T("WinInet FTP Test"),MB_OK);<br />
}
<br />
}else{<br />
err = GetLastError();<br />
str.Format(_T("InternetConnect Error: %d"), err);<br />
MessageBox(str, _T("WinInet FTP Test"),MB_OK);<br />
}
<br />
if (!InternetCloseHandle(hInternet)) {<br />
err = GetLastError();<br />
str.Format(_T("Error %d"), err);<br />
MessageBox(str, _T("WinInet FTP Test"),MB_OK);<br />
}
<br />
}else{<br />
err = GetLastError();<br />
str.Format(_T("InternetOpen Failed with code %d"), err);<br />
MessageBox(str, _T("WinInet FTP Test"),MB_OK);<br />
}
<br />
}
-Ryan Bradley
|
|
|
|
|
Two problems. 1) InternetConnect() return a HINTERNET but you're treating it like it returns a bool . 2) You're passing the wrong handle to FtpPutFile() , you need to pass it the handle returned by InternetConnect() .
--Mike--
Visual C++ MVP
LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Outstanding! Thank you!
Ryan Bradley
Systems Engineer
Industrial Networks
|
|
|
|
|
Hi,
In release mode , the project is searching for MFC42UD.lib file.
Any idea why and where we have to chnge the project settings, because to my knowledge somebody tampered with the settings
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Dont worry.
I figured it myself.
Somebody has changed the release setting to debug settings.
cheers,
Super
------------------------------------------
Too much of good is bad,mix some evil in it
|
|
|
|
|
Hello everyone!
Am I reading my file correctly?
for (int i = 0; i <= HEIGHT/32; i++)<br />
{<br />
char * curLine = new char[WIDTH/32];<br />
f[x]->getline(curLine, WIDTH/32);<br />
<br />
for (int j = 0; j <= WIDTH/32; j++)<br />
{<br />
<br />
char v = curLine[j];<br />
<br />
if (!f[x]->good())<br />
return;<br />
<br />
if (x == 0)<br />
fputc(v, outputz);
I noticed that if I open the file in Notepad, the character counter says 16, but if I count the chars with my fingers, I only get 15!
I want to get each line, and then write each character in that line to another file, individually. What's the right way of doing it? Much thanks!
PS: I've been struggling with this program for more than 1 month... I suck...
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
Update! I got the main problem away (NULL characters showing up at end of each line)
But now, the last line doesn't get written... Here's the updated code:
for (int i = 0; i <= HEIGHT/32; i++)<br />
{<br />
char * curLine = new char[WIDTH/32];<br />
f[x]->getline(curLine, WIDTH/32);<br />
<br />
for (int j = 0; j < WIDTH/32-1; j++)<br />
{<br />
<br />
char v = curLine[j];<br />
<br />
if (!f[x]->good())<br />
return;<br />
<br />
if (x == 0)<br />
fputc(v, outputz);
Much thanks!
Lord Kixdemp
www.SulfurMidis.com
www.SulfurSoft.tk
[ftp://][http://][hotline://]tsfc.ath.cx
|
|
|
|
|
hi,
i'm new to c++, still learning it. i am trying to learn some basic registry functions for use in other programs i may make. i have a subkey: currentuser/software/name/program
inside "program" i have a few values (all strings). how can i get the list of all values in the subkey?
i'm looking for the simplest possible way.RegCloseKey(hKey);
thanks in advance,
sam kline
-- modified at 18:46 Friday 17th February, 2006
|
|
|
|
|
|
ok, i've tried this code, but i cant figure out how to display 'cchValue'. any ideas?
thanks in advance,
sam kline
TCHAR achKey[MAX_KEY_LENGTH];
DWORD cbName;
TCHAR achClass[MAX_PATH] = TEXT("");
DWORD cchClassName = MAX_PATH;
DWORD cSubKeys=0;
DWORD cbMaxSubKey;
DWORD cchMaxClass;
DWORD cValues;
DWORD cchMaxValue;
DWORD cbMaxValueData;
DWORD cbSecurityDescriptor;
FILETIME ftLastWriteTime;
HKEY hKey;
DWORD i, retCode;
char temp[9999];
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
RegOpenKeyEx(HKEY_CURRENT_USER, TEXT("Software\\name\\something"), 0, KEY_QUERY_VALUE, &hKey);
retCode = RegQueryInfoKey(
hKey,
achClass,
&cchClassName,
NULL,
&cSubKeys,
&cbMaxSubKey,
&cchMaxClass,
&cValues,
&cchMaxValue,
&cbMaxValueData,
&cbSecurityDescriptor,
&ftLastWriteTime);
for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
{
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i, achValue, &cchValue, NULL, NULL, NULL, NULL);
if (retCode == ERROR_SUCCESS )
{
sprintf(temp, "%d: %s - ", i, achValue);
somelistbox.AddString(temp);
}
}
RegCloseKey(hKey);
-- modified at 10:55 Saturday 18th February, 2006
|
|
|
|
|
You can use this function:
Here you have to pass the valueName to access it's value.
Specify the Root key where your subkey is located
CString YourClassName::GetValueFromRegistry(CString regValuName)
{
char lszValue[255];
CString str ;
HKEY hKey;
LONG returnStatus;
DWORD dwType=REG_SZ;
DWORD dwSize=255;
returnStatus = RegOpenKeyEx(HKEY_CURRENT_USER, "currentuser\\software\\name\\program", 0L, KEY_ALL_ACCESS, &hKey);
if (returnStatus == ERROR_SUCCESS)
{
returnStatus = RegQueryValueEx(hKey,regValuName, NULL, &dwType,(LPBYTE)&lszValue, &dwSize);
if(returnStatus == ERROR_SUCCESS)
{
str = (LPCTSTR)lszValue;
}
else
{
str="";
}
}
else
{
str="";
}
RegCloseKey(hKey);
return str;
}
Cheers
"Peace of mind through Technology"
|
|
|
|
|
oh, i just realized that that code worked!
thanks a lot!
sam kline
|
|
|
|
|
Hi everybody,
I want to include few external DLL files into my executable file as a static Library.
Microsoft Visual C++ can do that with MFC,my question is: How can I do to insert external DLL's files?
I hope any body can help me!
Thanks
aLx
aLx
|
|
|
|
|
@LX wrote: I want to include few external DLL files into my executable file as a static Library.
That is not possible.
John
|
|
|
|
|
|