Making a C++ dll for VB6

Discussion of chess software programming and technical issues.

Moderator: Ras

Cardoso
Posts: 363
Joined: Thu Mar 16, 2006 7:39 pm
Location: Portugal
Full name: Alvaro Cardoso

Making a C++ dll for VB6

Post by Cardoso »

Hi,
I'm making an engine + GUI for turkish checkers and I'm adapting my old program Profound for portuguese checkers to do this.
Profound for portuguese checkers used some dlls made by me in the old PowerBasic compiler.
Since I'm using VB6 for the GUI I want to make a dll in c++ to generate the moves for the GUI.
VB6 doesn't have support for bitwise operations for 64bit integers so I need c++ to do this and I'm using Visual Studio 2022 for this.
The dll for move generation has it's own log file so I can be sure the functions are working correctly. And they are, the log file shows that the move generation is working flawlessly. Also it has to be 32bit as VB6 generates 32bit applications.
The problem is that my VB6 GUI crashes after the call to the dll function to generate the moves.

So I decided to make to make a simple dll with a function that just add 2 numbers and return the result and the GUI still crashes.
SO I wonder what I'm doing wrong. Does someone has a clue ? Do I have to change some switches in the solution properties? thx
On my VB6 GUI I have the following declaration:

Code: Select all

Public Declare Function CppAdd2Numbers Lib "Add2Numbers.dll" (ByVal a As Long, ByVal b As Long) As Long
And in Visual studio I have:

Code: Select all

// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.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 MYDLL_API __declspec(dllexport)

extern "C" int MYDLL_API CppAdd2Numbers(int a, int b) {
    int r;
    r = a + b;
    return r;
}
Also I added a def file with the following

Code: Select all

LIBRARY
CppAdd2Numbers=CppAdd2Numbers