Click here to Skip to main content
15,888,521 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Loading .PNG image windows GDI Pin
CPallini20-Mar-08 6:33
mveCPallini20-Mar-08 6:33 
GeneralOutlookAddin related problem. Pin
ritz123420-Mar-08 2:50
ritz123420-Mar-08 2:50 
GeneralRe: OutlookAddin related problem. Pin
_AnsHUMAN_ 20-Mar-08 2:54
_AnsHUMAN_ 20-Mar-08 2:54 
GeneralRe: OutlookAddin related problem. Pin
ritz123420-Mar-08 3:05
ritz123420-Mar-08 3:05 
GeneralUsing C/C++ DLL at Visual Basic 6.0 [modified] Pin
Scmitd20-Mar-08 1:04
Scmitd20-Mar-08 1:04 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
CPallini20-Mar-08 1:24
mveCPallini20-Mar-08 1:24 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
Scmitd20-Mar-08 2:55
Scmitd20-Mar-08 2:55 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 [modified] Pin
CPallini20-Mar-08 5:23
mveCPallini20-Mar-08 5:23 
DLL definition file (CRCDLL.def)
LIBRARY	"CRCDLL"
EXPORTS ComputeCrc


DLL header file (CRCDLL.h)
void __stdcall ComputeCrc(int CRCType, BYTE *Data, int Length, BYTE *TransmitFirst, BYTE *TransmitSecond);


DLL source file (CRCDLL.cpp)
#include "stdafx.h"
#include "CRCDLL.h"

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
		break;
	}
    return TRUE;
}

#define CRC_A 1
#define CRC_B 2

//#define BYTE unsigned char

unsigned short UpdateCrc(unsigned char ch, unsigned short *lpwCrc)
{
	ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
	ch = (ch^(ch<<4));
	*lpwCrc = (*lpwCrc >> 8)^((unsigned short)ch << 8)^((unsigned short)ch<<3)^((unsigned short)ch>>4);
	return(*lpwCrc);
}

void  __stdcall ComputeCrc(int CRCType, BYTE *Data, int Length, BYTE *TransmitFirst, BYTE *TransmitSecond)
{
	unsigned char chBlock;
	unsigned short wCrc;
	switch(CRCType) 
	{
	case CRC_A:
		wCrc = 0x6363;
		break;
	case CRC_B:
		wCrc = 0xFFFF; 
		break;
	default:
		return;
	}
	do 
	{
		chBlock = *Data++;
		UpdateCrc(chBlock, &wCrc);
	} while (--Length);

	if (CRCType == CRC_B)
		wCrc = ~wCrc;
	
	*TransmitFirst = (BYTE) (wCrc & 0xFF);
	*TransmitSecond = (BYTE) ((wCrc >> 8) & 0xFF);
	return;
}


Visual Basic sample code (actually it is VBA, I haven't VB6 here).
Private Declare Sub ComputeCrc Lib "CRCDLL.dll" _
(ByVal CRCType As Long, Data As Byte, ByVal Length As Long, TrnasmitFirst As Byte, TransmitSecond As Byte)

Private Sub CommandButton1_Click()
    Dim Data(2) As Byte
    Dim TransmitFirst As Byte
    Dim TransmitSecond As Byte
    Data(0) = &H12
    Data(1) = &H34
    Call ComputeCrc(1, Data(0), 2, TransmitFirst, TransmitSecond)
End Sub


Hope that helps.
Please note, VB code assumes the DLL is in the same folder of the VB6 executable, change it according to your needs.

BTW an oldie goldie: http://support.microsoft.com/?scid=kb%3Ben-us%3B106553&x=12&y=15[^]
Smile | :)

If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.

This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke


modified on Thursday, March 20, 2008 11:35 AM

GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
David Crow20-Mar-08 3:13
David Crow20-Mar-08 3:13 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
CPallini20-Mar-08 3:19
mveCPallini20-Mar-08 3:19 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
Scmitd20-Mar-08 4:09
Scmitd20-Mar-08 4:09 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
David Crow20-Mar-08 4:11
David Crow20-Mar-08 4:11 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
Scmitd20-Mar-08 4:31
Scmitd20-Mar-08 4:31 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
David Crow20-Mar-08 4:49
David Crow20-Mar-08 4:49 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
Scmitd20-Mar-08 4:32
Scmitd20-Mar-08 4:32 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
led mike20-Mar-08 4:26
led mike20-Mar-08 4:26 
GeneralRe: Using C/C++ DLL at Visual Basic 6.0 Pin
Scmitd20-Mar-08 4:37
Scmitd20-Mar-08 4:37 
QuestionWhat i need to do in VC++ 6 to activate the creation of dump file in crash ? Pin
Yanshof20-Mar-08 0:57
Yanshof20-Mar-08 0:57 
AnswerRe: What i need to do in VC++ 6 to activate the creation of dump file in crash ? Pin
Paresh Chitte20-Mar-08 1:57
Paresh Chitte20-Mar-08 1:57 
QuestionCreateDialog Question Pin
Programm3r19-Mar-08 22:40
Programm3r19-Mar-08 22:40 
GeneralRe: CreateDialog Question Pin
Rajkumar R19-Mar-08 23:11
Rajkumar R19-Mar-08 23:11 
QuestionRe: CreateDialog Question Pin
Programm3r19-Mar-08 23:16
Programm3r19-Mar-08 23:16 
GeneralRe: CreateDialog Question Pin
Rajkumar R19-Mar-08 23:35
Rajkumar R19-Mar-08 23:35 
GeneralRe: CreateDialog Question Pin
James R. Twine20-Mar-08 1:35
James R. Twine20-Mar-08 1:35 
GeneralRe: CreateDialog Question Pin
Programm3r20-Mar-08 1:39
Programm3r20-Mar-08 1:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.