Hello guys,
I have loaded akrip32.dll and can get handle within a function, but cannot get it when calling the function in main()
Please help me

app.cpp

#include <iostream>
//testing function below

//main application
int main()
{
    CDRip instance;
    DWORD ver = instance.GetVersion();
    LPGETCDHAND cdhandle;
    HCDROM handle ;
    handle = instance.GetCDHandle(cdhandle);
    std::cout<<"The Handle is: "<<handle<<std::endl;

    //wait!
    std::cin.get();

    return 0;
}

main.cpp

#include <iostream>
#include "main.h"
//Get CD handle
HCDROM CDRip::GetCDHandle(LPGETCDHAND lpcd ){

    //define a pointer to the function
    typedef HCDROM (*ptrGetCDHandle)(LPGETCDHAND lpcd );
    //Create a pointer function to access the DLL function
    ptrGetCDHandle GCDHandle;

    //Load the DLL
    HINSTANCE hDLL = LoadLibrary("akrip32.dll");
    //DLL loaded successful?
    if (hDLL!=0){
        std::cout<<"Loaded DLL"<<std::endl;
        //Get Function address
        GCDHandle = (ptrGetCDHandle)GetProcAddress(hDLL, "GetCDHandle");
        // Function loaded Succesful?
        if (GCDHandle !=0){
            LPGETCDHAND ptrCDHandle;
            HCDROM test_handle = GCDHandle(ptrCDHandle);
            return test_handle;

            FreeLibrary(hDLL);
        }
        // Function Loading failed
        else{
            std::cout<<"Error, can't load function GetVersion!"<<std::endl;
            FreeLibrary(hDLL);
        }
    }
    //DLL Loading failed
    else std::cout<<"Error! Cannot Load Library"<<std::endl;

}

main.h

#include <windows.h>

//structs used in below functions
#define  MAXIDLEN   64
#define  MAXCDLIST  8

  typedef struct
  {
    char vendor[9];
    char prodId[17];
    char rev[5];
    char vendSpec[21];
  } CDINFO, *PCDINFO, FAR *LPCDINFO;

  typedef struct
  {
    BYTE    ha;
    BYTE    tgt;
    BYTE    lun;
    BYTE    pad;
    char    id[MAXIDLEN + 1];
    CDINFO  info;
  } CDREC, *PCDREC, FAR *LPCDREC;

  typedef struct
  {
    BYTE    max;
    BYTE    num;
    CDREC   cd[MAXCDLIST];
  } CDLIST, *PCDLIST, FAR *LPCDLIST;



 typedef struct _GETCDHAND
  {
    BYTE size;
    BYTE ver;
    BYTE ha;
    BYTE tgt;
    BYTE lun;
    BYTE readType;
    BOOL jitterCorr;
    BYTE numJitter;
    BYTE numOverlap;   // was previously numSave
  } PACKED GETCDHAND, *PGETCDHAND, FAR *LPGETCDHAND;

//The TOC structure is used for calls to ReadTOC. It is essentially a direct copy of the format returned by the SCSI READ TOC (0x43) command.
  typedef struct
  {
    BYTE   rsvd;
    BYTE   ADR;
    BYTE   trackNumber;
    BYTE   rsvd2;
    BYTE   addr[4];
  } PACKED TOCTRACK;

  typedef struct
  {
    WORD   tocLen;
    BYTE   firstTrack;
    BYTE   lastTrack;
    TOCTRACK tracks[100];
  } PACKED TOC, *PTOC, FAR *LPTOC;


//CD Handle
typedef HANDLE HCDROM;


class CDRip{
   
    public:

        //constructor
        //CDRip::CDRip(){}
        
        
        // Opens a handle to a CD-ROM device with the options specified in the lpcd parameter.
        HCDROM GetCDHandle(LPGETCDHAND lpcd );//implement
        //Just returns a handle to CDROM
        HCDROM RetHandle(void);



};

Thanks

In both instances you are misusing the GetCDHandle() function.

The function takes a pointer to an extant GETCDHAND struct.

HCDROM    hcd;
GETCDHAND cdhand;
hcd = GetCDHandle( &cdhand );

Hope this helps.

[edit] There might be other errors too... but I've got to go now [/edit]

I have scratched my head to just get a handle and I'm hitting a wall somewhere. Please help to correct me. I cannot get the handle to cdrom and hence I cannot proceed

with thanks

main.h hasn't changed


main.cpp

//Get CD handle
HCDROM CDRip::GetCDHandle(LPGETCDHAND lpcd ){

    //define a pointer to the function
    typedef HCDROM (*ptrGetCDHandle)(LPGETCDHAND lpcd );
    //Create a pointer function to access the DLL function
    ptrGetCDHandle GCDHandle;

    //Load the DLL
    HINSTANCE hDLL = LoadLibrary("akrip32.dll");
    //DLL loaded successful?
    if (hDLL!=0){
        std::cout<<"Loaded DLL"<<std::endl;
        //Get Function address
        GCDHandle = (ptrGetCDHandle)GetProcAddress(hDLL, "GetCDHandle");
        // Function loaded Succesful?
        if (GCDHandle !=0){
            //GETCDHAND cdhandle;
            //lpcd = &cdhandle;
            //GCDHandle(lpcd);
            std::cout<<"Handle in function is: "<<GCDHandle(lpcd)<<std::endl;

            FreeLibrary(hDLL);
        }
        // Function Loading failed
        else{
            std::cout<<"Error, can't load function GetVersion!"<<std::endl;
            FreeLibrary(hDLL);
        }
    }
    //DLL Loading failed
    else std::cout<<"Error! Cannot Load Library"<<std::endl;
    return 0;

}

app.cpp

# include "main.h"
#include <iostream>
//testing function below

//main application
int main()
{
    CDRip instance;    
    GETCDHAND cdhandle;
    LPGETCDHAND lpcd;
    lpcd = &cdhandle;
    HCDROM handle ;
    handle = instance.GetCDHandle(lpcd);
    std::cout<<"The Handle is: "<<handle<<std::endl;

Thanks friend for pointing that out!
I guess I was sleeping-awake when I was writing that.
How can I tell it return 0 and then ask why :)
It now returns 1x0 as handle. Let me see if I can proceed!
Thanks again

Please someone help me testing what handle do you get.
When I use the handle to get Table of content, I get garbages on screen and they differ each time I run the application. Before I check the TOC function, I need to be sure that the handle is valid.

So just remove the return 0 and then tell me what handle does it print. And if you have any idea if the handle is valid :)
Thanks for giving your time

Have anyone here ever worked or is planning to work with this akrip32.dll? I would like to finish my project which is ripping CD with it, and I'm facing alot of walls. If anyone is willing to advise me on the issue, warmly welcome :)

Here is the full code and DLLs
Please feel free to modify them and repost them.
The most important for me now is to learn through the project, so feel free to point out errors or poor coding styles
Thanks for your valuable time

This article has been dead for over six months. Start a new discussion instead.