How to call this c code?

How to call this c code?

Postby Horizon » Thu Dec 20, 2018 8:13 pm

Hi,

In order to checklicence with dongle I have a c code. but I do not know how to use it?

Can you help me?

Code: Select all  Expand view  RUN
typedef char* (CALLBACK* __stdcall ODFunctionType)(char *a,char *b);
 HINSTANCE hDLL = NULL;
 ODFunctionType OD_CheckLicence;

{
 char* DongleResult;
 char OkeyLicenceKey[96];
 char SessionID[32];

 OkeyLicenceKey = "5D45E9CB4825075DB9752C46C4EB6931852E8A7BAA52610FBA8255C521F674FB4B27C5955729F9FE33058BF3743A7B2F14C3F75D1F8A785134FD368D2194FA9F";

 hDLL = LoadLibrary(TEXT("OkeyDongleLibrary.dll"));
 OD_CheckLicence = (ODFunctionType)GetProcAddress(hDLL, "OD_CheckLicence");

 DongleResult = OD_CheckLicence(SessionID,OkeyLicenceKey);
}


okey_dongle.c
Code: Select all  Expand view  RUN
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include "okey_dongle.h"


int Load_Functions(void)
{
HINSTANCE hDLL=NULL;
#ifdef _M_X64
hDLL = LoadLibrary(TEXT("OkeyDongleLibraryx64.dll"));
#else
hDLL = LoadLibrary(TEXT("OkeyDongleLibrary.dll"));
#endif
if (hDLL==NULL) return 1;
else
    {
        //Importing functions from DLL
       
               
                OD_Login=(function_type_2) GetProcAddress(hDLL,"OD_Login");
                OD_Logout=(function_type_1) GetProcAddress(hDLL,"OD_Logout");
                OD_IsLogined=(function_type_0) GetProcAddress(hDLL,"OD_IsLogined");
                OD_StrToHex=(function_type_1) GetProcAddress(hDLL,"OD_StrToHex");
                OD_HexToStr=(function_type_1) GetProcAddress(hDLL,"OD_HexToStr");
                OD_StrToBase64=(function_type_1) GetProcAddress(hDLL,"OD_StrToBase64");
                OD_Base64ToStr=(function_type_1) GetProcAddress(hDLL,"OD_Base64ToStr");
                OD_HexToBase64=(function_type_1) GetProcAddress(hDLL,"OD_HexToBase64");
                OD_Base64ToHex=(function_type_1) GetProcAddress(hDLL,"OD_Base64ToHex");
                OD_Enc=(function_type_2) GetProcAddress(hDLL,"OD_Enc");
                OD_Dec=(function_type_2) GetProcAddress(hDLL,"OD_Dec");
                OD_ShowError=(function_type_1) GetProcAddress(hDLL,"OD_ShowError");
                OD_ChangeError=(function_type_2) GetProcAddress(hDLL,"OD_ChangeError");
                OD_Info=(function_type_1) GetProcAddress(hDLL,"OD_Info");
                OD_ReadSerial=(function_type_0) GetProcAddress(hDLL,"OD_ReadSerial");
                OD_ReadHash=(function_type_1) GetProcAddress(hDLL,"OD_ReadHash");
                OD_CheckLicence=(function_type_2) GetProcAddress(hDLL,"OD_CheckLicence");
                OD_MD5File=(function_type_1) GetProcAddress(hDLL,"OD_MD5File");
                OD_MD5Text=(function_type_1) GetProcAddress(hDLL,"OD_MD5Text");
                OD_SHA1File=(function_type_1) GetProcAddress(hDLL,"OD_SHA1File");
                OD_SHA1Text=(function_type_1) GetProcAddress(hDLL,"OD_SHA1Text");
                OD_DesEnc=(function_type_2) GetProcAddress(hDLL,"OD_DesEnc");
                OD_DesDec=(function_type_2) GetProcAddress(hDLL,"OD_DesDec");
                OD_3DesEnc=(function_type_2) GetProcAddress(hDLL,"OD_3DesEnc");
                OD_3DesDec=(function_type_2) GetProcAddress(hDLL,"OD_3DesDec");
                OD_SignText=(function_type_2) GetProcAddress(hDLL,"OD_SignText");
                OD_SignFile=(function_type_2) GetProcAddress(hDLL,"OD_SignFile");
                OD_VerifyText=(function_type_4) GetProcAddress(hDLL,"OD_VerifyText");
                OD_VerifyFile=(function_type_4) GetProcAddress(hDLL,"OD_VerifyFile");
                OD_WriteMemory=(function_type_4) GetProcAddress(hDLL,"OD_WriteMemory");
                OD_ReadMemory=(function_type_2) GetProcAddress(hDLL,"OD_ReadMemory");
                OD_DeleteMemory=(function_type_2) GetProcAddress(hDLL,"OD_DeleteMemory");
                OD_WriteProtectedMemory=(function_type_6) GetProcAddress(hDLL,"OD_WriteProtectedMemory");
                OD_ReadProtectedMemory=(function_type_4) GetProcAddress(hDLL,"OD_ReadProtectedMemory");
                OD_DeleteProtectedMemory=(function_type_3) GetProcAddress(hDLL,"OD_DeleteProtectedMemory");
                OD_ReadMaxUser=(function_type_1) GetProcAddress(hDLL,"OD_ReadMaxUser");
                OD_ReadCredit=(function_type_1) GetProcAddress(hDLL,"OD_ReadCredit");
                OD_ReadLogin=(function_type_1) GetProcAddress(hDLL,"OD_ReadLogin");
                OD_DataFillArray=(function_type_3) GetProcAddress(hDLL,"OD_DataFillArray");
                OD_DataReadArray=(function_type_2) GetProcAddress(hDLL,"OD_DataReadArray");
                OD_DataFillFromMemory=(function_type_2) GetProcAddress(hDLL,"OD_DataFillFromMemory");
                OD_DataWriteToMemory=(function_type_2) GetProcAddress(hDLL,"OD_DataWriteToMemory");
                OD_DataAdd=(function_type_1) GetProcAddress(hDLL,"OD_DataAdd");
                OD_DataSub=(function_type_1) GetProcAddress(hDLL,"OD_DataSub");
                OD_DataAnd=(function_type_1) GetProcAddress(hDLL,"OD_DataAnd");
                OD_DataOr=(function_type_1) GetProcAddress(hDLL,"OD_DataOr");
                OD_DataXor=(function_type_1) GetProcAddress(hDLL,"OD_DataXor");
                OD_DataInverse=(function_type_2) GetProcAddress(hDLL,"OD_DataInverse");
                OD_DataSum=(function_type_3) GetProcAddress(hDLL,"OD_DataSum");
                OD_DataExchange=(function_type_3) GetProcAddress(hDLL,"OD_DataExchange");
                OD_DataEnc=(function_type_2) GetProcAddress(hDLL,"OD_DataEnc");
                OD_DataDec=(function_type_2) GetProcAddress(hDLL,"OD_DataDec");
                OD_EncWithMemoryKey=(function_type_2) GetProcAddress(hDLL,"OD_EncWithMemoryKey");
                OD_DecWithMemoryKey=(function_type_2) GetProcAddress(hDLL,"OD_DecWithMemoryKey");
                OD_EncWithKey=(function_type_3) GetProcAddress(hDLL,"OD_EncWithKey");
                OD_DecWithKey=(function_type_3) GetProcAddress(hDLL,"OD_DecWithKey");
        return 0;

    }

}
 


okey_dongle.h
Code: Select all  Expand view  RUN
/* O-Key Dongle API declarations
 *
 */


/*!
 *
 *  Copyright OKYANUS BİLİŞİM TEKNOLOJİLERİ
 *
 *  13-02-2009
 */



#include <stdio.h>
#include <windows.h>
#include <conio.h>

#ifndef __OKEY_DONGLE_H
#define __OKEY_DONGLE_H


//Common variables
char* serial_number;
char* control;
char plaintext[32];
char ciphertext[34];
char session[32];


//Function type declarations
typedef char* (CALLBACK* __stdcall function_type_0)();
typedef char* (CALLBACK* __stdcall function_type_1)(char *parameter_1);
typedef char* (CALLBACK* __stdcall function_type_2)(char *parameter_1,char *parameter_2);
typedef char* (CALLBACK* __stdcall function_type_3) (char *parameter_1,char *parameter_2, char *paramater_3);
typedef char* (CALLBACK* __stdcall function_type_4) (char *parameter_1,char *parameter_2, char *paramater_3,char *paramater_4);
typedef char* (CALLBACK* __stdcall function_type_5) (char *parameter_1,char *parameter_2, char *paramater_3,char *paramater_4,char *paramater_5);
typedef char* (CALLBACK* __stdcall function_type_6) (char *parameter_1,char *parameter_2, char *paramater_3,char *paramater_4,char *paramater_5,char *paramater_6);


/* Function declarations
 * Please refer to documentation for detailed function descriptions.
 */



function_type_2 OD_Login;
function_type_1 OD_Logout;
function_type_0 OD_IsLogined;
function_type_1 OD_StrToHex;
function_type_1 OD_HexToStr;
function_type_1 OD_StrToBase64;
function_type_1 OD_Base64ToStr;
function_type_1 OD_HexToBase64;
function_type_1 OD_Base64ToHex;
function_type_2 OD_Enc;
function_type_2 OD_Dec;
function_type_1 OD_ShowError;
function_type_2 OD_ChangeError;
function_type_1 OD_Info;
function_type_0 OD_ReadSerial;
function_type_1 OD_ReadHash;
function_type_2 OD_CheckLicence;
function_type_1 OD_MD5File;
function_type_1 OD_MD5Text;
function_type_1 OD_SHA1File;
function_type_1 OD_SHA1Text;
function_type_2 OD_DesEnc;
function_type_2 OD_DesDec;
function_type_2 OD_3DesEnc;
function_type_2 OD_3DesDec;
function_type_2 OD_SignText;
function_type_2 OD_SignFile;
function_type_4 OD_VerifyText;
function_type_4 OD_VerifyFile;
function_type_4 OD_WriteMemory;
function_type_2 OD_ReadMemory;
function_type_2 OD_DeleteMemory;
function_type_6 OD_WriteProtectedMemory;
function_type_4 OD_ReadProtectedMemory;
function_type_3 OD_DeleteProtectedMemory;
function_type_1 OD_ReadMaxUser;
function_type_1 OD_ReadCredit;
function_type_1 OD_ReadLogin;
function_type_3 OD_DataFillArray;
function_type_2 OD_DataReadArray;
function_type_2 OD_DataFillFromMemory;
function_type_2 OD_DataWriteToMemory;
function_type_1 OD_DataAdd;
function_type_1 OD_DataSub;
function_type_1 OD_DataAnd;
function_type_1 OD_DataOr;
function_type_1 OD_DataXor;
function_type_2 OD_DataInverse;
function_type_3 OD_DataSum;
function_type_3 OD_DataExchange;
function_type_2 OD_DataEnc;
function_type_2 OD_DataDec;
function_type_2 OD_EncWithMemoryKey;
function_type_2 OD_DecWithMemoryKey;
function_type_3 OD_EncWithKey;
function_type_3 OD_DecWithKey;


//ERROR MESSAGES

//If an error occurs, these error messages will return in string format.
//Refer to documentation for detailed description of error messages.


/*

OD_ERROR 0001 : Controller Object Creating Error
OD_ERROR 0002 : Device Not Found
OD_ERROR 0003 : Device Read/Write Access Error
OD_ERROR 0006 : Invalid_Array_ID
OD_ERROR 0007 : Invalid Memory Adress
OD_ERROR 0008 : Operation Error E:
OD_ERROR 0009 : File Not Found
OD_ERROR 0011 : Invalid Licence
OD_ERROR 0012 : Error Not Changed
OD_ERROR 0014 : Memory Write Error
OD_ERROR 0017 : Invalid Input
OD_ERROR 0018 : Device Is Blocked
OD_ERROR 0019 : Device Not Ready
OD_ERROR 0020 : Connection Error
OD_ERROR 0023 : Unknown Request
OD_ERROR 0024 : Session ID Not Found
OD_ERROR 0026 : Maximum User Limit Exceeded
OD_ERROR 0027 : Invalid Limit Value
OD_ERROR 0028 : Operation Time Out
OD_ERROR 0029 : Invalid Session ID
OD_ERROR 0031 : Maximum Limit Exceeded
OD_ERROR 0032 : Invalid Password
OD_ERROR 0033 : Module Is Not Active
OD_ERROR 0034 : Invalid Attribute
OD_ERROR 0035 : Access Denied
OD_ERROR 0036 : Invalid PIN
OD_ERROR 0037 : Device Is Permanently Blocked
OD_ERROR 0038 : Invalid Module ID
OD_ERROR 0039 : Invalid Device Parameter
OD_ERROR 0040 : Invalid Key
OD_ERROR 0041 : Invalid Array Index
OD_ERROR 0042 : Invalid Operation Mode
OD_ERROR 0043 : Invalid Error Code
OD_ERROR 0044 : Invalid Signature
OD_ERROR 0045 : Verification Failed
OD_ERROR 0046 : Invalid PIN Format
OD_ERROR 0047 : Private Key Not Found
OD_ERROR 0048 : Invalid User Limit Value
OD_ERROR 0049 : Can Not Locate O-Key XNet Server
OD_ERROR 0050 : Invalid IP Range

*/


// ACKNOWLEDGE MESSAGES

//Some functions return acknowledge messages.

/*

OD_OK 0001 : Limit Set Ok
OD_OK 0002 : Write Ok
OD_OK 0003 : Delete Ok
OD_OK 0005 : LogOut Ok
OD_OK 0006 : Change Error Ok
OD_OK 0007 : Operation Ok
OD_OK 0008 : ShowError Ok
OD_OK 0009 : Connection Ok
OD_OK 0012 : Verification Ok

*/



int Load_Functions(void);


#endif
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: How to call this c code?

Postby AntoninoP » Fri Dec 21, 2018 9:08 am

should be something like:
Code: Select all  Expand view  RUN

#include "FiveWin.ch"

static hLib
DLL32 FUNCTION OD_CheckLicence( param1 AS LPSTR,param2 AS LPSTR) AS LPSTR ;
      PASCAL FROM If( IsExe64(), "OD_CheckLicence", "OD_CheckLicence@4" ) ;
      LIB hLib

proc main()
    local SessionID,cResult
    local OkeyLicenceKey := "5D45E9CB4825075DB9752C46C4EB6931852E8A7BAA52610FBA8255C521F674FB4B27C5955729F9FE33058BF3743A7B2F14C3F75D1F8A785134FD368D2194FA9F"
   hLib := LoadLibraty("OkeyDongleLibrary.dll")
   cResult := OD_CheckLicence(@SessionID,OkeyLicenceKey)
 


but I am not an expert of this syntax, maybe someone can help you better.
AntoninoP
 
Posts: 375
Joined: Tue Feb 10, 2015 9:48 am
Location: Albenga, Italy

Re: How to call this c code?

Postby Horizon » Fri Dec 21, 2018 10:00 am

AntoninoP wrote:should be something like:
Code: Select all  Expand view  RUN

#include "FiveWin.ch"

static hLib
DLL32 FUNCTION OD_CheckLicence( param1 AS LPSTR,param2 AS LPSTR) AS LPSTR ;
      PASCAL FROM If( IsExe64(), "OD_CheckLicence", "OD_CheckLicence@4" ) ;
      LIB hLib

proc main()
    local SessionID,cResult
    local OkeyLicenceKey := "5D45E9CB4825075DB9752C46C4EB6931852E8A7BAA52610FBA8255C521F674FB4B27C5955729F9FE33058BF3743A7B2F14C3F75D1F8A785134FD368D2194FA9F"
   hLib := LoadLibraty("OkeyDongleLibrary.dll")
   cResult := OD_CheckLicence(@SessionID,OkeyLicenceKey)
 


but I am not an expert of this syntax, maybe someone can help you better.


Thank you. I will try.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 59 guests