| | |
Strange DLL problem...
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
Hi, I recently was trying to learn how to write DLLs and was doing ok until I ran across this interesting problem. It seems that the function is not receiving the last argument.
Here is my code for the dll
and here is my .def file
I am using visual studio C++ 2005 to write the dll and am using VB to call it. When I call sum it returns the value of x.. if I tell the dll to return y I always get 0 ... I can't figure it why. When I added more arguments to the function I found that it was always the last variable that always is received as 0. What is happening? What am I doing wrong?
Here is my code for the dll
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { return TRUE; } _declspec (dllexport) int _stdcall sum(int x , int y) { return (x+y); }
and here is my .def file
C++ Syntax (Toggle Plain Text)
LIBRARY example1 EXPORTS sum @1
I am using visual studio C++ 2005 to write the dll and am using VB to call it. When I call sum it returns the value of x.. if I tell the dll to return y I always get 0 ... I can't figure it why. When I added more arguments to the function I found that it was always the last variable that always is received as 0. What is happening? What am I doing wrong?
how did you declare it in your vb program? what you posted appears to be correct. But you don't need both the *.def file and use of _dllspec(__export) -- all you need is one of them.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
The VB declare statement should be:
where example1.dll is the name of your dll file.
VB Syntax (Toggle Plain Text)
declare function sum lib "example1.dll" (byval x as long, byval y as long) as long
•
•
Join Date: Sep 2008
Posts: 3
Reputation:
Solved Threads: 0
•
•
•
•
The VB declare statement should be:
where example1.dll is the name of your dll file.VB Syntax (Toggle Plain Text)
declare function sum lib "example1.dll" (byval x as long, byval y as long) as long
C++ Syntax (Toggle Plain Text)
Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Button1.Text = Str(sum(CInt(TextBox1.Text), CInt(TextBox2.Text))) End Sub Private Declare Function sum Lib "example1.dll" (ByVal x As Long, ByVal y As Long) As Long End Class
but I still have that problem
Last edited by daggath; Sep 6th, 2008 at 8:18 pm. Reason: clicked on post to soon.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
You do need both the *.def file and use of _dllspec(__export) if you want clean names exported from the dll (at least in MinGW and VC++2008). Without the def file, you will export a function something like "?sum@@YGHHH@Z"; with the .def file the function name exported is "sum"
Last edited by dougy83; Sep 6th, 2008 at 8:28 pm.
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
What language are you using to call the dll?? You said VB above (I assumed vb6), are you sure it's not VB.net or Visual Basic 2005/6/7/8?? vb6 successors have different data types to vb6 - I think long is 64bits, so use Int32 instead of long for the declare statement.
Last edited by dougy83; Sep 6th, 2008 at 8:33 pm.
![]() |
Similar Threads
- DLL problem in Borland C++ (C++)
- HiJackThis and Panda titanium problem (Viruses, Spyware and other Nasties)
- Rundll32 Problem (Viruses, Spyware and other Nasties)
- Sorry, another "bridge.dll" problem.. here's my HJT log. (Viruses, Spyware and other Nasties)
- smiehlp.dll? (Viruses, Spyware and other Nasties)
- Strange IE Hijack (Viruses, Spyware and other Nasties)
- error message on startup: bridge.dll missing (hijackthis log inside) (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Staggered input from file
- Next Thread: array help
| Thread Tools | Search this Thread |
add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data delete desktop directshow dll download dynamic encryption error file forms fstream function functions game getline google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory microsoft multidimensional newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






