Calling a DLL (TWAIN_32)

Hello, I am a novice c++ programmer trying to call the TWAIN dll. They have an example in thier specification, but I can't get it to work. I either get Error 1 error C2197: 'int (__stdcall *)(void)' : too many arguments for call rc=(*pProc)(&twApp, 0, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, Wrapper::Caller); (the "TWAIN" way)
or Error 1 error C2197: 'FARPROC' : too many arguments for call rc=pProc(&twApp, 0, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, Wrapper::Caller);
when I tried to call it the way I found described by microsoft. I don't know what I am doing wrong.

Here's the code I used to Load the DLL:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#define TWAIN_Dll "TWAIN_32.DLL"
static HANDLE hDllModule;
//static DSMENTRYPROC pProc;
static FARPROC pProc;
static TW_IDENTITY twApp;

bool LoadDll()
    {
      //long Ordinal;

      //hDllModule=LoadLibrary(LPCWSTR (TWAIN_Dll));
      hDllModule=LoadLibraryA(TWAIN_Dll);
      //if (hDllModule>=(HANDLE)VALID_HANDLE) 
      if (hDllModule!=NULL) 
      //{   Ordinal=MAKELONG(1,0);
      //   pProc=GetProcAddress(HMODULE (hDllModule), LPCSTR(MAKEINTRESOURCE(Ordinal)));
      {   pProc=GetProcAddress(HMODULE (hDllModule), LPCSTR(MAKEINTRESOURCE(1)));
         if (pProc!=0)
            bDllLoaded=true;
         else
            bDllLoaded=false;}
      else
         bDllLoaded=false;

      return bDllLoaded;
    } 


I found the MAKELONG & Ordinal method on a forum, but it doesn't change the results.

Any assistance is appreciated. Thanks for looking!
OK, I've made some progress with help from Jim Watters. It seems I needed the twain.h file. Copying and pasting the needed constants and structures isn't enough. Now I have a new problem.

The call now fails with a message in the calling application (VB.NET) Attempted to read or write protected memory. This is often an indication that other memory is corrupt. Do I have to do something if I am calling unmanaged code from managed code? A VB.NET app is calling the C++ function which is failing.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 bool Wrapper::DSM_Open()
    {
		int rc, hWnd;

        ...deleted code...
        lstrcpyA (twApp.Version.Info, "2.0");
        twApp.Version.Language = TWLG_ENGLISH_USA;
        twApp.Version.MajorNum = 2;
        twApp.Version.MinorNum = 0;

        //Open the DSM (Data Source Manager)
	hWnd = Wrapper::Caller;
	rc=(*pProc)(&twApp, 0, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) hWnd);
	rc=pProc(&twApp, 0, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, Wrapper::Caller);
        if (rc==TWRC_SUCCESS)
            return  true;
        else
            return false;
}
    


I tried calling it 4 different ways with the same error. The proc tries to write a number to twApp.Id so I assume that is what's causing the problem. Thanks for any assistance.
After more research it may be an issue of having unmanaged code write to a structure allocated by managed code. Can anyone point a beginning C++ programmer somewhere to get assistance?

Thanks.
I am going to do this entirely in VB, so I am abandoning it.
Topic archived. No new replies allowed.