using DLL

B

Bruno Guerpillon

Hi

In the code Below, im trying to use a dll to encrypt a password.
The function in the dll is supposed to be sent a Char and to give out a
Char.
I'm really beginner, and i dont manage to make this Work.
Any clue ?

Regards

Bruno

#include <windows.h>
#include <string.h>
#include <stdio.h>
// typedef int __stdcall (*FCTX)(char *aChaine);
typedef char (*FCTX)(char*);
// const char* __stdcall (*FCTX)(char *aChaine);
#define FUNCTION_NAME "Cypher"
#define MODULE_NAME "cypher.dll"

int main (int argc, char *argv[]) {
// static char ModPath[255]="C:\\WINDOWS\\SYSTEM32\\";

FCTX Fn_Ptr;
HMODULE ModId;
char passwd;

// strcat(ModPath, MODULE_NAME);
// ModId = LoadLibrary(ModPath);
ModId = LoadLibrary(MODULE_NAME);
Fn_Ptr = (FCTX)GetProcAddress(ModId, FUNCTION_NAME);
passwd = Fn_Ptr("motdff");
FreeLibrary(ModId);
printf ("Après appel de la fonction dans le module, le status = %s\n",
passwd);
printf ("Appuyez sur une touche :");
getchar();
return 0;
}
 
B

Bill Medland

Bruno said:
Hi

In the code Below, im trying to use a dll to encrypt a password.
The function in the dll is supposed to be sent a Char and to give out a
Char.
I'm really beginner, and i dont manage to make this Work.
Any clue ?

Regards

Bruno

#include <windows.h>

You would probably be better asking in a windows-centred group such as
comp.os.ms-windows.programmer.win32
#include <string.h>
#include <stdio.h>
// typedef int __stdcall (*FCTX)(char *aChaine);
typedef char (*FCTX)(char*);

Presumably that should be char * (*FCTX)(char *)
// const char* __stdcall (*FCTX)(char *aChaine);
#define FUNCTION_NAME "Cypher"
#define MODULE_NAME "cypher.dll"

int main (int argc, char *argv[]) {
// static char ModPath[255]="C:\\WINDOWS\\SYSTEM32\\";

FCTX Fn_Ptr;
HMODULE ModId;
char passwd;

Again, char *?
// strcat(ModPath, MODULE_NAME);
// ModId = LoadLibrary(ModPath);
ModId = LoadLibrary(MODULE_NAME);
Fn_Ptr = (FCTX)GetProcAddress(ModId, FUNCTION_NAME);
passwd = Fn_Ptr("motdff");
FreeLibrary(ModId);

That has almost certainly just invalidated the memory that passwd points to.
Maybe you need to strdup the passwd reply.
printf ("Après appel de la fonction dans le module, le status = %s\n",
passwd);
printf ("Appuyez sur une touche :");
getchar();
return 0;
}

It is hard to say anything else without knowing what that dll says is
supposed to be done.
 
B

Barry Schwarz

Hi

In the code Below, im trying to use a dll to encrypt a password.
The function in the dll is supposed to be sent a Char and to give out a
Char.
I'm really beginner, and i dont manage to make this Work.
Any clue ?

Regards

Bruno

#include <windows.h>
#include <string.h>
#include <stdio.h>
// typedef int __stdcall (*FCTX)(char *aChaine);
typedef char (*FCTX)(char*);

Make up you mind. Is the function argument a char (as you stated
above) or a char* (as you coded)?

Why did you change the return type? Since you did not implement the
function, why do you think you can change the type it returns? (There
is no problem with you assigning the returned value to a different but
compatible type but that is not what you did.)
// const char* __stdcall (*FCTX)(char *aChaine);
#define FUNCTION_NAME "Cypher"

C is case sensitive. Are you sure the function name is capitalized?
#define MODULE_NAME "cypher.dll"

int main (int argc, char *argv[]) {
// static char ModPath[255]="C:\\WINDOWS\\SYSTEM32\\";

FCTX Fn_Ptr;
HMODULE ModId;
char passwd;

// strcat(ModPath, MODULE_NAME);
// ModId = LoadLibrary(ModPath);
ModId = LoadLibrary(MODULE_NAME);

Are you this function will work with an incomplete path name?
Fn_Ptr = (FCTX)GetProcAddress(ModId, FUNCTION_NAME);
passwd = Fn_Ptr("motdff");

Does the function ever attempt to modify the array argument? Since
the prototype does not say "const char*," there is an implied
assumption that it might. If it does, this will invoke undefined
behavior because the array you pass is a string literal and modifying
it is not allowed.
FreeLibrary(ModId);
printf ("Après appel de la fonction dans le module, le status = %s\n",
passwd);
printf ("Appuyez sur une touche :");

Better to say "press ENTER". Pressing any other key will cause the
system to wait patiently until you do.
getchar();
return 0;
}

Better to ask these questions in a Windows or VC newsgroup since many
of the questions deal with details that are not part of the language
(the topic here) but part of library only that compiler has.


Remove del for email
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,083
Latest member
SylviaHarr

Latest Threads

Top