473,385 Members | 1,740 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A problem about call Dll

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!!
Aug 21 '08 #1
6 2652
ÓÚÑó 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
Aug 21 '08 #2
ÓÚÑó 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
Aug 21 '08 #3
"ÓÚÑó" <yu****@bjzh.com.cnwrote in message
news:g8**********@news.cn99.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

Aug 21 '08 #4
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
Aug 21 '08 #5
"ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½" 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,his 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.hheader, 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.hand <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.

Aug 21 '08 #6

"Martin Ambuhl" <ma*****@earthlink.netwrote in message
news:g8**********@registered.motzarella.org...
"ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï ¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½" 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

Aug 21 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
28
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are...
3
by: fdsl ysnh | last post by:
--- python-list-request@python.orgдµÀ: > Send Python-list mailing list submissions to > python-list@python.org > > To subscribe or unsubscribe via the World Wide Web, > visit >...
35
by: wired | last post by:
Hi, I've just taught myself C++, so I haven't learnt much about style or the like from any single source, and I'm quite styleless as a result. But at the same time, I really want nice code and I...
15
by: Simon Harvey | last post by:
Hi everyone, I am fairly new to learning about xsl and xml, but one thing I have noticed is that anyone offering a tutorial or lesson on it seems to think that its the most incredible invention...
17
by: kj | last post by:
How can one test if a pointer has been "freed" (i.e. with free())? My naive assumption was that such a pointer would equal NULL, but not so. Thanks, kj -- NOTE: In my address everything...
15
by: Sam Sungshik Kong | last post by:
Hello! A disposable object's Dispose() method can be called either explicitly by the programmer or implicitly during finalization. If you call Dispose, the unmanaged resources are released...
6
by: Danny Ni | last post by:
Hi, If I want to programatically add rows to a DataTable, do I call AcceptChanges per row? Or do I call AcceptChanges after all rows added? TIA
10
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL,...
4
by: Giampaolo Rodola' | last post by:
Hi, I'm trying to implement an asynchronous scheduler for asyncore to call functions at a later time without blocking the main loop. The logic behind it consists in: - adding the scheduled...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.