How To Create a DLL

jdeproffesional

Active Member
Many people are intrested to create a DLL in c++ inorder to link it and use with many other 3 party software, ariba,siebel,VB,..etc. i will explaina code to create a DLL that can be linked to insert a record into JDE table.
#include <jde.h>
//#include <statreg.h>
//#include <statreg.cpp>
//#include <comutil.h>

//#include <atlconv.h>
#include <stdAfx.h>
#include <F55inter.h>
#include <stdio.h>
#include <stdlib.h>

//#include <windows.h>
//#include <objbase.h>
//#include <comdef.h>

//#include <stdio.h>
//#include <conio.h>
//#include <iostream.h>
//#include <wchar.h>







//#define IABMBFDataStruct IDSD0100041
//#define SERVER OLESTR("FSN_JDEDB")


extern "C" __declspec( dllexport ) void CATCHORACLE (int);



extern void CATCHORACLE (int xx)



{

HREQUEST hRequest = NULL;
HENV hEnv = NULL;
HUSER hUser = NULL;
NID idTable = NID_F55INTER;
ID idIndex = ID_F55INTER_AN8;
F55INTER dsStructToInsert;
JDEDB_RESULT rcode;
JDE_MEMORY_POOL GPoolCommon;
char szEnv[11] = "DEV733";
char szUser[11] = "demo";
char szPwd[11] = "demo";
// FILE *stream;


GPoolCommon = jdeMemoryManagementInit();
// memset((void *) &hEnv, (int) '\0', sizeof(hEnv));
// stream = fopen ("c:\do.txt","w");
if ((rcode = JDB_InitEnvOvr(&hEnv,szEnv,szUser,szPwd)) != JDEDB_PASSED)
{
jdeMemoryManagementTerminate();
// printf ("JDB ENV FAILED\n");
// fprintf(stream,"FAIL\n",);

}
else
{
// printf ("JDB ENV Sucssess\n");


}

if ((rcode =JDB_InitUser(hEnv,&hUser,NULL,JDEDB_COMMIT_AUTO)) != JDEDB_PASSED)
{

// printf ("JDB USER FAILED\n");

}

else
// if ((rcode =JDB_InitUser(hEnv,&hUser,NULL,JDEDB_COMMIT_AUTO)) == JDEDB_PASSED)
{

// printf ("JDB USER Success\n");

}


if ((rcode = JDB_OpenTable(hUser, idTable, idIndex, NULL, (int)0, NULL, &hRequest)) != JDEDB_PASSED)
{
// printf("JDB_OpenTable failed\n");
//return (0);
}
else
{
// printf("JDB_OpenTable Sucess\n");

}
GPoolCommon = jdeMemoryManagementInit();
memset((void *) &dsStructToInsert, (int) '\0', sizeof(dsStructToInsert));

strncpy(dsStructToInsert.indesc, " AA1234567", sizeof(dsStructToInsert.indesc));
ParseNumericString (&dsStructToInsert.inan8,"204");



if ((rcode = JDB_InsertTable(hRequest, idTable, 0, &dsStructToInsert)) != JDEDB_PASSED)

{
// printf("JDB_InsertTable failed\n");
}
else
{
// printf("JDB_InsertTable Success\n");
}

if ((rcode = JDB_CloseTable(hRequest)) != JDEDB_PASSED)
{
// printf("JDB_CloseTable failed\n");
}
else
{
// printf("JDB_CloseTable Success\n");
}


if(hUser)JDB_FreeUser(hUser);
if(hEnv)JDB_FreeEnv(hEnv);
jdeMemoryManagementTerminate();

//return (0);

}
The EXTERN statment at the begining is your key and function name.
Make sure to open C++ and create a new project choose WIN32 dynamic link library.

Good luck.
 
Are you compiling this in VC++ 6.0? Or Busbuild? I can't get it to link in VC6. It complains about not finding all the JDB Stuff. Maybe I need to change the make file?
 
you have also to check the format alignement, if you want to use into JDe :
use the stdcall to compile with a 1 byte alignement (with visual c++)
 
Back
Top