|
how can i give a a value more than 32700 to an integer
i tried long int,unsigned long but all of these doenst work
my code is:
#include <stdio.h>
#include <conio.h>
int a,b,c,max,min,av;
void main() {
clrscr();
printf("1.number:");
scanf("%d",&a);
printf("2.number:");
scanf("%d",&b);
printf("3.number:");
scanf("%d",&c);
//------------------------max number
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else
max=c;
//---------------------min number
if(a
|
|
|
|
|
An unsigned long can hold numbers from 0 to 4,294,967,295. ints can hold values from –2,147,483,648 to 2,147,483,647.*
* Actually, this is platform dependent, so this may not be true in your case.
Anonymous wrote:
if(a min=a;
You're missing a closing paren.
Anonymous wrote:
else if(b min=b;
Same here.
What platform are you using to compile and run this program? What error(s) are you getting when you compile this? run this?
Jon Sagara
There is no spoon.
Best Miniputt score: 21
Sonork ID: 100.9999 jonsagara
|
|
|
|
|
By your use of clrscr(), you're compiling on a possibly 16 bit platform/compiler? If so, it may be that you need to scanf(%u,...) to input an unsigned integer.
|
|
|
|
|
How do I create a template that takes a member function as a parameter?
Here's what I'm trying to do
<pre>
void MyClass::DoSomething(int x)
{
}
MyClass::blah()
{
foo<MyClass>(DoSomething);
}
</pre>
<pre>
????
template <class C>
void foo(FunctionPointer fp)
{
int x = 0;
for (int i=0; i<10; i++)
{
fp(x);
}
}
</pre>
<b>Todd Smith
CPUA 0x007 ... shaken not stirred</b>
|
|
|
|
|
Google for 'functors' and you should hit it.
(Boy, hows that for a detailed response! )
|
|
|
|
|
That landed me in boost territory. It was a little daunting at first but here's what I came up with.
#include "stdafx.h"
#include <boost bind.hpp="">
#include "debugstr.h"
class CTest
{
public:
void Test(const char* str)
{
printf("member function: %s", str);
}
};
template <class f="">
void foo(F f)
{
for (int i=0; i<10; i++)
{
char buf[128] = {0};
sprintf(buf, "test %i\n", i);
f(buf);
}
}
void Test(const char* str)
{
printf("global function: %s", str);
}
int main(int argc, char* argv[])
{
CTest test;
foo(boost::bind(&CTest::Test, boost::ref(test), _1));
foo(boost::bind(Test, _1));
return 0;
}
Todd Smith
CPUA 0x007 ... shaken not stirred
|
|
|
|
|
It is doable, but it is not correct unless your member function is a staic one. Why do not pass pointer to that class as a parameter to foo() and inside foo() call p->DoSomething()
soptest
|
|
|
|
|
Well if you can keep the same parameters for the function then this might work
template <typename T>
class FunctionPointer {
typedef void (T::*FuncPtr)(int);
FunctionPointer( T* src, FuncPtr func ):m_source( src ), m_func(func) {};
void doit( int x ) {
(m_source->*m_func)(x)
}
FuncPtr m_func;
T* m_source;
};
template <typename T>
void foo(FunctionPointer<T> fp )
{
int x = 0;
for (int i=0; i<10; i++) {
fp.doit(x);
}
}
MyClass::blah()
{
foo( FunctionPointer<MyClass>(this, DoSomething) );
}
would this work ?
|
|
|
|
|
Hi All,
I'm deriving a view class from the CHtmlView, and sticking this in a child frame window of an MDI app. Anyway, I've got a toolbar with a forward and backward arrow for going forward and backward through the CHtmlView's history list. Going forward and back is simple enough (through CHtmlView::GoForward, and CHtmlView::GoBack), but how can I determine if there are previous entries or next entries in the history list of the browser from the current page? What I need is something like a CanGoBack or a CanGoForward method so I can update the buttons on the toolbar in the CmdUI handler.
Thanks,
Aaron
|
|
|
|
|
keybord event can generate a keystroke ,but how do you direct this keystroke to a particular window or its message queue.
|
|
|
|
|
I posted this a while back, and have been meaning to clean it up and offer it to the god of FAQ - maybe it will help.
|
|
|
|
|
I am sorry,I could not locate anything on 'this' link.
|
|
|
|
|
Ok - here is the example I posted, which should be made into a SendKeys type function. Here I hardcoded a known window handle - (Calculator).
Basically, the trick is to post messages for keydown and keyup, and its nice to format the lparam properly.
#include "stdafx.h"
#include "crtdbg.h"
#include "conio.h"
#include "windows.h"
#include "winbase.h"
int main(int argc, char* argv[])
{
HWND hwnd = (HWND) 0x025c;
INT Vk;
INT Scan;
CHAR character[2];
CHAR oemchar[2];
CHAR ch;
do {
while(!_kbhit());
ch = getch();
character[0]=ch;
character[1]='\0';
Vk = VkKeyScan(character[0]) & 0xFF;
CharToOem(character, oemchar);
Scan = OemKeyScan(oemchar[0]) & 0xFF;
printf("Key = %c, VK code = %d, scan = %d\n", ch, Vk, Scan);
UINT lKeydata = 0;
UINT mask = 1;
lKeydata |= mask;
lKeydata |= Scan << 15;
::PostMessage(hwnd, WM_KEYDOWN, Vk, lKeydata);
lKeydata |= mask;
lKeydata |= Scan << 15;
lKeydata |= mask << 31;
::PostMessage(hwnd, WM_KEYUP, Vk, lKeydata);
}
while(1);
return 0;
}
|
|
|
|
|
thanks!! it is a great help
|
|
|
|
|
Hi everybody,
Is ther a way [read: a program] to find out what functions a dll is exporting? Is there a tool with MVS that can do this?
To learn more about this I chose the default implementation of a sample dll in VC++: New->Projects->Win32 dynamic link-library.
Now, there's a test function called fnDllTest (my project is called DllTest) which is exported like this:
__declspec(dllexport) int fnDllTest(void)
{
return 42;
}
Now, I created a simple console application which should call this dll function. I loaded the dll using LoadLibrary and that works fine... BUT, now I wish to get the function fnDllTest through the use of GetProcAddress but I can't seem to get it working!
If the dll and the console app loading the dll are residing in the same place then the call to GetProcAddress should look like this right?
blabla = (blabla)GetProcAddress(libPtr, "fnDllTest");
where libPtr is the return value of LoadLibrary... What kind of type should blabla be of?
I haven't found any documentation on how to call dll exported functions...
Thx for all your help,
/Tommy
|
|
|
|
|
find the tool called DUMPBIN. it will tell you the function names. i'm not sure if it can tell you the params, tho.
-c
Smaller Animals Software, Inc.
Few things are harder to put up with than the annoyance of a good example.
Mark Twain
|
|
|
|
|
Thx!
I tried and this was the result:
...
ordinal hint RVA name
1 0 0000100A ?fnDllTest@@YAHXZ
...
What does this tell me? I can't very likely do like this, or...?
... GetProcAddress(libPtr, "?fnDllTest@@YAHXZ");
I mean, there must be a way for me to know what the exporting function name will look like when it is me writing them...?
THx for your help!
/Tommy
|
|
|
|
|
blabla will be a function pointer that is the same type as the function that you are loading. This is why it is hard to use functions in a dll without a header file or good documentation.
In the example that you have given, here would be the function pointer that you would declare:
int (fnDllTestPtr*)(void);
fnDllTestPtr becomes the name of the function pointer type. To use this you would now call this:
fnDllTestPtr fnDllTest = (fnDllTestPtr)GetProcAddress(libPtr, "fnDllTest);
As far as determining which functions are exported pragmatically, you will need to traverse the PE file structure of the DLL in order to read the exports section. Lookup Mike Peitrics article on the PE file format. He created a smaple program called PEDump.
|
|
|
|
|
No, that can't be right...
It crashed when I tried to do that... I mean, shouldn't there be a typedef somewhere?
|
|
|
|
|
Hi again,
Shouldn't it be:
int (*fnDllTestPtr)(void);
and then
fnDllTestPtr = (???)GetProcAddress(libPtr, "fnDllTest");
but I don't know what to put in '???'...
/Tommy
|
|
|
|
|
I am sorry, this is the correct declaration for the function pointer. Typedef it so that you can use it later.
typedef int(*fnDllTestPtr)(void);
Also, if you do not encapsulate the function that you are exporting with extern "c"{ }, then the function will be name mangled, and you will have to include the mangled name in order to load it. So for the function that you have sent in, it should be managled like this:
?fnDllTest@@YAHXZ
Before you attempt to call the function, you should check the return value from GetProcAddress to insure that the function was found and properly pointed to. If the function fails, it will return NULL.
Here is the code that you should use.
typedef int(*fnDllTestPtr)(void);
fnDllTestPtr fp = (fnDllTestPtr)::GetProcAddress(libPtr, "?fnDllTest@@YAHXZ");
if (NULL == fp)
{
MessageBox(NULL, "an error has occurred. The function did not load.", "error", MB_OK);
}
else
{
int i = fp();
}
|
|
|
|
|
Thx Kilowatt! It worked!
But how on earth can it be possible to conclude the above code from the documentation?!?!
First of all; how can this assignment work? Isn't fnDllTestPtr a function pointer variable...?
But again, thx!
/Tommy
|
|
|
|
|
Move casting to left side of assignment:
EDIT - it should be FARPROC &
(FARPROC & )fnDllTestPtr = GetProcAddress(...);
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
Use Dependency Walker (depends). There is a (usually old) version in the Platform SDK. You can get the latest version from http://www.dependencywalker.com.
|
|
|
|
|
The function name in a DLL can be viewed using Dependency Walker that comes along with Microsoft Developer Studio 6.0. It shows as Depends in the tools panel of Developer studio
Sanjay Mishra
|
|
|
|