|
I did. (HINT: take a close look at how you are extracting the data)
|
|
|
|
|
You are only ever going to be working with the last two numbers read, as you are not testing to see if num or nextnum are larger than largest before over writing the value. If the file contains only one column of numbers you only need to read into num (infile >> num) and also have the one if statement testing against largest in the while loop.
Try the following.
int main ()
{
int num, nextnum, largest;
ifstream infile;
infile.open ("testfile");
infile >> num >> nextnum;
largest = 0;
while (!infile.fail())
{
if (num > largest)
{
largest = num;
}
if (nextnum > largest)
{
largest = nextnum;
}
infile >> num >> nextnum;
}
cout << "Largest: " << largest << endl;
infile.close ();
return 0;
}
Michael Martin
Pegasystems Pty Ltd
Australia
martm@pegasystems.com
+61 413-004-018
|
|
|
|
|
Hi I am trying to call a DLL (for testing I use the SetWindowTextA function from User32.dll)
Everything seems correct to me...and the program compiles and links fine, except that on executing it, it given an illegal operation. I have checked that SetWindowTextA is in User32.dll, so I guess it should work?
Here is the code:
#include<windows.h>
#define TAILLE_MAX 40
void main()
{
char *szFuncName = "SetWindowTextA";
char *szDllName = "User32.dll";
HINSTANCE hLibrary;
HWND hwnd;
char szOldWndTitle[TAILLE_MAX];
char *szNewWndTitle = "Changed Title";
BOOL RetVal;
GetConsoleTitle(szOldWndTitle, TAILLE_MAX);
hwnd = FindWindow(NULL, szOldWndTitle);
__asm
{
push szDllName
call LoadLibrary
mov hLibrary, eax
push szFuncName
push hLibrary
call GetProcAddress ;eax recieves function pointer
push szNewWndTitle
push hwnd
call eax
mov RetVal, eax
push hLibrary
call FreeLibrary
}
}
Any ideas what is wrong?
Thanks in advance
|
|
|
|
|
Hi,
how can I load, view, modify and save
domain users's ACL registrered into HKCR\AppID\object's GUID\AccessPermission subkey of registry?
I've already used RegQueryValueEx Api in my C++ program but i don't know to interpret ACL in it.
Help me, thanks!
|
|
|
|
|
Can I use CTime in a Win32 application?
SomW
|
|
|
|
|
I never tried but I think Yes you can,but you must include <winafx.h> header.
|
|
|
|
|
Short answer: no
long answer: It can be done, but it's very tricky to rip a single class out of MFC; and adding full MFC support to the project is probably not what you want either.
|
|
|
|
|
Hi,
My problem is that I have to write a function that will at runtime accept a name of a dll and a name of a function contained in that dll and then call that function. The obvious problem is that a compile time we don't know the return type of a function be be called and the number and types of arguments to be passed to the dll.
My guess is that we'd have to use assembler code in __asm blocks to pass any number of parameters of any types by manually pushing them into the stack.
But then of what type do I declare the function pointer that will take the adress of function returned by GetProcAddress?
Any Answers/Suggestions?
Thanks in advance,
Mvworld
|
|
|
|
|
Hello, the codegurus around the world.;)
In fact, I don't know what your assembler code does?
But, if the assembler code can call Java class, you can use JINI to call DLL
file which you created.
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Hi,
I have been trying to use run time linking with Dll files. I am new to Windows programming, so I am confused what is causing the error in my program.
I am trying to use run time linking to change the Window Title of a Console widow.
Here is the code:
#include
typedef BOOL (WINAPI *LPFNDLLFUNC) (HINSTANCE hInstance, char *dwText);
void main()
{
HINSTANCE hLibrary;
LPFNDLLFUNC lpfnDllFunc;
BOOL RetVal;
char dwString[] = "Changed Text";
HWND hwnd;
char pszWindowTitle[40];
GetConsoleTitle(pszWindowTitle, 40);
hwnd = FindWindow(NULL, pszWindowTitle);
hLibrary = LoadLibrary("USER32.DLL");
lpfnDllFunc = (LPFNDLLFUNC) GetProcAddress(hLibrary, "SetWindowText");
RetVal = lpfnDllFunc(hLibrary, dwString);
}
It compiles and links fine, but it performs an illegal operation on running it.
On debugging I get the following message:
Unhandeled exception in Testing.exe:OxC0000005:Access Violation
Any ideas?
|
|
|
|
|
Hello, the codegurus around the world;)
First of all, I don't know the exact answer, but
have you ever written C or C++ code?
>> I am new to Windows programming.
So, you know C?
I mean, why don't you use if-else statement to check if the function returns the right value.
1) Check if FindWindow works fine?
2) If 1) works, go to 3)
3) Check if LoadLibrary works fine?
4) If 3) works, go to 4)
5) Check if GetProcAddress works fine?
6) If 5) works, go t 7)
7) Try to use SetWidnowText(...)
I think that any programmer needs this kind of approaches even though we use Java or C++.
Anyway, I think that SetWindowText's first arguement passes HWND, not HINSTANCE?
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Have you traced through the code yet? You'll see that lpfnDllFunc is NULL. That's because there is no function "SetWindowText". There are "SetWindowTextA" and "SetWindowTextW" for ANSI and Unicode, respectively. Your code is using plain chars, so use the ANSI version.
--Mike--
http://home.inreach.com/mdunn/
The Signature, back by popular demand: Buffy. Pajamas.
|
|
|
|
|
Hi mate,
Yeah I took note of it, just careless mistake I suppose.
Thanks a ton though
|
|
|
|
|
FindWindow(A/W) and SetWindowText(A/W) both lives in user32.dll. If you are using FindWindow using static link, why do you need runtime linking for SetWindowText?
|
|
|
|
|
This problem is a part of a larger study problem I have for my college project.
I am basically experimenting with all the calling conventions etc...and this will finally be used in code for XEmacs, which is a unix originated text editor.
|
|
|
|
|
How can I implement an application to send data over a network (by using a custom-made OLEDB provider) the same way commercial DBMS communicate with data consumers?
Ernesto Moscoso Cam
|
|
|
|
|
Hi All,
I have a BSTR string variable via ADO Recordset Getstring method. In the BSTR string has null
character('\0'). How can I get rid them of in a common way(Of course I can loop from start of
BSTR, but I want a directly way).
Thank you.
chenzhu
|
|
|
|
|
Hello, the codegurus around the world.;)
In fact, I don't understand your question a little bit.
Do you want to take off "NULL" word from Column (display)?
Or do you want to take off '\0' from all strings in Column?
Or I miss something?
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Dear Masaaki Onishi,
The last effect is my desire. I get a BSTR string has '\t' separator between columns and '\n'
between rows. But int the string has excaptional '\0' just before a '\t'. I can not transform
it to CString by W2A or WideCharToMultiByte functions directly because these annoying '\0'.
Thanks.
chenzhu
|
|
|
|
|
Hello, the codegurus around the world.;)
Do you try to use ADO in MFC or COM(ActiveX)?
If you use ADO in MFC, we can use DataGrid control and this member function to display the data.
As a result, we don't need to care about each data string.
I often use Datagrid for ADO in MFC.
Actually, MSDN has a good example called AdoDataGrid(?).
However, if you want to use CListView or something to display your data, you may need to work
your problem.
Anyway, I want to sleep now.
So, someone migh help you, or if I have a time....
Have a nice day!
-Masaaki Onishi-
|
|
|
|
|
Dear Masaaki Onishi,
Thank you very much. Yes, I want a control to display the data. Actualy I am making a ATL control and the ATL control hold one Grid that accept format string in that pattern. The
common usage is a VB project, which is the client of ATL COM control, opens one database
and get one recordset, and then pass it into ATL control. Of course I can loop through whole
recordset, read variant from every fields and assemble a CString by myself, but that is
too tiresome.
If you have waked up now has have a good mood, give me a advice.
thank you.
chenzhu
|
|
|
|
|
Hi do anyone know how to link a file in C++ whith a line of code like #pragma or something... I don't want to set it in the project settings box...
|
|
|
|
|
Try this:
#pragma comment(lib,"something.lib")
|
|
|
|
|
|
can you help me to add an icon to a CFileDialog
|
|
|
|