fordy, when i use dynamic link libraries i dont need to use C linkage. why does mkyong have to? heres the source:
Code:
//library.cpp
#include <windows.h>
#include <stdio.h>
#define DLL_EXPORT
#include "library.h"
int bitFlag[8]={1,2,4,8,16,32,64,128}; //Bit flags for binary operations
void Notify(HWND hwnd,LPCTSTR str)
{
MessageBox(hwnd,str,"Notification",MB_OK);
return;
}
void Notify(HWND hwnd,long int num)
{
char *chTemp;
chTemp=(char *)malloc(11);
ltoa(num,chTemp,10);
Notify(hwnd,chTemp);
free(chTemp);
return;
}
int GetBit(BYTE byte,int bit)
{
if ( (bit<0)||(bit>7) )
{
Notify(NULL,"bit request error; \nmust be between 0 and 7");
exit(ERR_GETBIT);
}
if (byte&bitFlag[bit])
return 1;
return 0;
}
void SetBit(BYTE &byte,int bit,int state)
{
if (GetBit(byte,bit))
{
if (state)
return;
else
byte-=bitFlag[bit];
return;
}
if (state)
byte+=bitFlag[bit];
else
return;
return;
}
char *BinaryString(BYTE byte)
{
char *tmpStr;
tmpStr=(char *)malloc(9);
for (int i=0;i<8;i++)
tmpStr[7-i]=GetBit(byte,i)+48;
tmpStr[8]=0;
return tmpStr;
}
Code:
//library.h
#ifndef libraryH
#define libraryH
#ifndef DLL_EXPORT
#define DS __declspec(dllimport)
#else
#define DS __declspec(dllexport)
#endif
#define ERR_GETBIT 101
void DS Notify(HWND,LPCTSTR);
void DS Notify(HWND,long int);
int DS GetBit(BYTE,int);
void DS SetBit(BYTE,int,int);
char DS *BinaryString(BYTE);
#endif
how is it different?