Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dll question 1

Status
Not open for further replies.

bernardsylunar

Programmer
Feb 9, 2005
25
PH
hi everyone!

i'm new to Visual C++ and i try to create my own dll and call it from my Visual Basic 6.0 program. i've created a function IsStringEqual that will check if the two strings are equal. here's my code...

In Visual C++

int _stdcall IsStringEqual(char string1, char string2, int discardCase)
{
if (discardCase == 1)
{
string1 = tolower(string1);
string2 = tolower(string2);
}
if (string1 == string2)
return 1;
else
return 0;
}


In Visual Basic

Private Declare Function IsStringEqual Lib "E:\ynad\personal\program\vc++\MyDll\Release\MyDll.dll" (ByVal String1 As Any, ByVal String2 As Any, ByVal discardCase As Integer)

Private Sub Command1_Click()
Dim i
i = IsStringEqual(Text1.Text, Text2.Text, 0)
Debug.Print i
End Sub

-------------------------------------

everytime i run my visual basic project and click the command button there's always an error message 'Bad DLL calling convention'. i try to remove the _stdcall there's always the same error that i've encountered.

pls help...

thanks in advance

ynad
----
It is foolish to listen to someone who will not listen to you.
 
I think Text maps to char*. Try
Code:
#include <string.h>
int _stdcall IsStringEqual(char* string1, char* string2, int discardCase)
{
    if (discardCase == 1)
        return _stricmp (string1, string2) == 0;
    else
        return strcmp (string1, string1) == 0;
}
 
xwb

thanks for your reply. i've copy and paste your code the still i got same error.

thanks again...

ynad
----
It is foolish to listen to someone who will not listen to you.
 
From the code snippet it is diffcult to see whether you're using 1 or 2 underscores in _stdcall. Have you tried with two? Better yet; use WINAPI, which resolves to the correct one dependent on your target platform, if i'm not mistaken...

And have you tried replacing the Any arguments with string arguments?



Greetings,
Rick
 
Hi Rick

Thnks for the reply.

i already tried replacing String with Any before and it did not work.

as you have said, i try using two underscores but i got the same error...

by the way, i'm still working on it anyway. i hope i can make it work a.s.a.p...

many thanks for your reply..




ynad
----
It is foolish to listen to someone who will not listen to you.
 
One more thing; did you link a module definition file with the dll? This is used to export the functions inside your dll.

Greetings,
Rick
 
yes, i included IsStringEqual in the EXPORTS list on the .def file

thanks




ynad
----
It is foolish to listen to someone who will not listen to you.
 
Last shot (it's that I don't have much time to test your stuff):

I see that your declare does not return a function return type; this will make it a variant by default, right? Variants are not 4 bytes (which is what your C function returns).

If this doesn't help; in the weekend I'll try to make the two projects you're making....

Greetings,
Rick
 
hi Rick,

you got it dude!!!

the return value in my VB declaration is what i missed.

a star for you!!!

btw, i got another problem. i try to register my dll but there's an error.

C:\MyDll.dll was loaded, but the DllRegisterServer entry point was not found.

DllRegisterServer may not be exported, or a corrupt version of C:\MyDll.dll may be in memory. Consider using PView to detect and remove it.


any idea on this?

thanks again...






ynad
----
It is foolish to listen to someone who will not listen to you.
 
It probably is a regular dll, and not a COM dll. Therefore it need not and can not be registered (if it were a COM dll you wouldn't need to use the declare from within VB, would you?)

Greetings,
Rick
 
oh i get it. i thought every dll should be first registered before using. i just copy it into the windows/system32 and it's working.

thanks a lot..

and thanks for the help...

another star

ynad
----
It is foolish to listen to someone who will not listen to you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top