Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > A problem about call Dll

Reply
Thread Tools

A problem about call Dll

 
 
Guest
Posts: n/a
 
      08-21-2008
Hi all!
I have a Dll like this:

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

__declspec (dllexport) int Add (int n)
{
int x;

x = 100 + n;

return x;
}

And I use this to call the Dll:

#include "windows.h"
#include "stdio.h"

int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int iCmdShow)
{
HINSTANCE hAdd;
FARPROC Add;

if(hAdd= LoadLibrary ("Add.dll"))
{
Add = GetProcAddress (hAdd, "Add");
printf ("%i\n", Add(100));
FreeLibrary (hAdd);
}

}

After compiling,there is an error:too many arguments to function.

Please tell me how can i correct my code. Thanks in advance!!


 
Reply With Quote
 
 
 
 
Willem
Guest
Posts: n/a
 
      08-21-2008
wrote:
) Hi all!
) I have a Dll like this:
)
) #include <windows.h>
<snip>
) Please tell me how can i correct my code. Thanks in advance!!

You'll have better luck asking in a newsgroup that deals with
windows programming, such as comp.os.ms-windows.programmer.*


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
 
Reply With Quote
 
 
 
 
jacob navia
Guest
Posts: n/a
 
      08-21-2008
wrote:
> Hi all!
> I have a Dll like this:
>
> #include <windows.h>
> #include <stdio.h>
> #include <stdlib.h>
>
> __declspec (dllexport) int Add (int n)
> {
> int x;
>
> x = 100 + n;
>
> return x;
> }
>
> And I use this to call the Dll:
>
> #include "windows.h"
> #include "stdio.h"
>
> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
> LPSTR lpCmdLine, int iCmdShow)
> {
> HINSTANCE hAdd;
> FARPROC Add;
>
> if(hAdd= LoadLibrary ("Add.dll"))
> {
> Add = GetProcAddress (hAdd, "Add");
> printf ("%i\n", Add(100));
> FreeLibrary (hAdd);
> }
>
> }
>
> After compiling,there is an error:too many arguments to function.
>
> Please tell me how can i correct my code. Thanks in advance!!
>
>


Using the free compiler lcc-win I do not get any errors. I do
get warnings about using FARPROC without a cast, and missing return
value from WinMain, but there are no errors.

Which compiler are you using?

Using Microsoft C, I do not get any warning or errors at all.


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Bartc
Guest
Posts: n/a
 
      08-21-2008
"" <(E-Mail Removed)> wrote in message
news:g8j967$rq9$(E-Mail Removed)99.com...

> #include "windows.h"
> #include "stdio.h"
>
> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
> LPSTR lpCmdLine, int iCmdShow)
> {
> HINSTANCE hAdd;
> FARPROC Add;
>
> if(hAdd= LoadLibrary ("Add.dll"))
> {
> Add = GetProcAddress (hAdd, "Add");
> printf ("%i\n", Add(100));
> FreeLibrary (hAdd);
> }
>
> }
>
> After compiling,there is an error:too many arguments to function.


Which function, Add?

I don't recognise the FARPROC and other types, but: you're calling Add()
with an int parameter, yet you've declared Add to have no parameters
(assuming FARPROC declares a function of some kind).

Also you may want to check that Add actually contains a valid function
address.

--
Bartc

 
Reply With Quote
 
jacob navia
Guest
Posts: n/a
 
      08-21-2008
Bartc wrote:
> I don't recognise the FARPROC and other types, but: you're calling Add()
> with an int parameter, yet you've declared Add to have no parameters
> (assuming FARPROC declares a function of some kind).
>
> Also you may want to check that Add actually contains a valid function
> address.
>


Normally FARPROC is
typedef int (CALLBACK *FARPROC)();

where CALLBACK is just _stdcall.

Now, in C, this is a prototype to a function pointer with
an unknown number of parameters.

In C++ however, the empty parameter list is just assumed
(void), and that could explain the warning...


--
jacob navia
jacob at jacob point remcomp point fr
logiciels/informatique
http://www.cs.virginia.edu/~lcc-win32
 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      08-21-2008
"���������������� ���������" wrote:
> Hi all!
> I have a Dll like this:


Then you probably have an implementation problem, not a C problem. For
those you need to ask in an implementation-specific newsgroup. You are
lucky, since there a several specifically for windows programming.
DLLs, in particular, are implementation details that have nothing at all
to do with C.


> #include <windows.h>

^^^^^^^^^^^
Note that <windows,h> is no part of the C language. It is, however,
part of the the Windows interface to that particular operating system.

> #include <stdio.h>
> #include <stdlib.h>


> __declspec (dllexport) int Add (int n)

^^^^^^^^^^ ^^^^^^^^^
And neither __declspec nor dllexport mean anything at all in C. They
may be defined in the <windows.h> header, but we can;t see them.

> {
> int x;
> x = 100 + n;
> return x;
> }


The body of this function could be collapsed down to
{ return 100 + n; }
The variable x serves no purpose at all.


> And I use this to call the Dll:
> #include "windows.h"

^^^^^^^^^^
> #include "stdio.h"

^^^^^^^
Unless you have your own personal copies of <windows.h> and <stdio.h>
that differ from the implementation-provided ones, and you mean to use
those instead of the implementation-provided headers, the "..." form is
almost always wrong.

>
> int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
> LPSTR lpCmdLine, int iCmdShow)


And look at all the things in that one line that have no meaning in C
without provided definitions, which you have not shown us. Those
include WINAPI, WinMain, HINSTANCE, and LPSTR. Note that all C programs
have a main() function in a hosted environment. You do not have one,
but are using WinMain(). You are using a C-like language designed for
use only in one particular environment. Newsgroups for that environment
abound.

> {
> HINSTANCE hAdd;
> FARPROC Add;


FARPROC doesn't mean anything either.

>
> if(hAdd= LoadLibrary ("Add.dll"))
> {
> Add = GetProcAddress (hAdd, "Add");
> printf ("%i\n", Add(100));
> FreeLibrary (hAdd);
> }
>
> }
>
> After compiling,there is an error:too many arguments to function.


When you ask this in the right place, be sure to tell them the actual
error message. You seem to have at least the functions LoadLibrary,
GetProcAddess, printf, and FreeLibrary, only one of those, printf, has a
defined meaning in C. You need to determine _which_ function has too
many arguments. You should then look up those functions in your
documentation. The only defined C function does not have the wrong
number of arguments, so it must be one of those implementation-provided
functions, so look in your implementation documentation. No C reference
can help you.

 
Reply With Quote
 
Bartc
Guest
Posts: n/a
 
      08-21-2008

"Martin Ambuhl" <(E-Mail Removed)> wrote in message
news:g8jfhv$h7t$(E-Mail Removed)...
> "���������������� ���������" wrote:


>> {
>> int x;
>> x = 100 + n;
>> return x;
>> }

>
> The body of this function could be collapsed down to
> { return 100 + n; }
> The variable x serves no purpose at all.


For that matter, the function serves little purpose either; just adding 100
to the argument would be better.

And the entire program can be further collapsed into:

#include <stdio.h>
int main(void) {
puts("200");
}

Which also eliminates the OP's problem

--
Bartc

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Second long argument to a JNI call on a Win32 DLL contains zero when it reaches the DLL pcarr01 Java 3 02-17-2005 09:30 AM
How to determine if a DLL is a COM DLL or .NET DLL Anushi ASP .Net 5 10-28-2004 01:59 PM
Why does Ruby use both tcl83.dll and tk83.dll (instead of just tk83.dll)? H. Simpson Ruby 4 08-03-2004 04:45 PM
mprapi.dll --> samlib.dll --> ntdll.dll issue. Some1 Computer Support 4 04-05-2004 02:02 AM
msvcrt.dll, msvcirt.dll, msvcrt20.dll and msvcrt40.dll, explanation please! Snoopy NZ Computing 16 08-25-2003 12:34 PM



Advertisments