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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Strings to DLL 1

Status
Not open for further replies.

jamez05

Programmer
Jul 29, 2005
130
0
0
US
I have some code that calls a DLL named James and passes
2 integers and a string to it:
Code:
int CallJames(void)
{ 
     /* get handle to dll */
     HINSTANCE hGetProcIDDLL = LoadLibrary("C:\\WINDOWS\\system32\\James.dll");

     /* get pointer to the function in the dll*/
     FARPROC lpfnGetProcessID = GetProcAddress(HMODULE(hGetProcIDDLL), "sum");

     /* Define the Function in the DLL for reuse. This is just prototyping
        the dll's function. A mock of it. Use "stdcall" for maximum compatibility.
    */
     typedef int (__stdcall * pICFUNC)(int,int,char*);

     pICFUNC MyFunction;
     MyFunction = pICFUNC(lpfnGetProcessID);

     char Msg[25];
	 /* The actual call to the function contained in the dll */ 
     int intMyReturnVal = MyFunction(1,2,Msg);

     /* Release the Dll */
     FreeLibrary(hGetProcIDDLL);

     /* The return val from the dll */
     return intMyReturnVal;
}

The James DLL code looks like this:
Code:
#include "stdafx.h"          // Standard MFC libraries


int _stdcall sum(char Msg, int x, int y) 
{
	
	strcpy(Msg,'got here');
	
	return x + y;

}

When I try to compile James.dll, I get problems with
the strcpy:
Code:
error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'

What am I doing wrong?
 
The error message should make it obvious. Msg is just a char, it should be a char*. A char holds only a single character, while a char* points to an array of characters that make up a string.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top