Author Topic: Microsoft Compiled BCXPP.dll  (Read 164 times)

Robert

  • Sr. Member
  • ****
  • Posts: 449
    • View Profile
Microsoft Compiled BCXPP.dll
« on: July 17, 2020, 12:00:18 PM »
When this code

Code: [Select]

$DLL STDCALL
FUNCTION ProcessLine (Src$) AS LONG EXPORT
  IF Src$ = "DISPLAY MESSAGE" THEN Src$ = "PRINT " + ENC$("MAGIC HAPPENS!")
  FUNCTION = 1
END FUNCTION


is translated with a 64 bit BCX 7.5.0 and compiled with this batch file

Code: [Select]

setlocal
@rem Created with BldBat Version.4.1.2 for Microsoft Visual Studio 2019 X64 (STDCALL DLL)
@ECHO OFF
IF NOT EXIST %1.cpp GOTO usage
PUSHD "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\"
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
POPD
IF EXIST %1.res GOTO res
IF NOT EXIST "res\%~1.rc" GOTO nores
ECHO Compiling resources.....
rc.exe /fo "%~1.res" /ires "res\%~1.rc"
:res
IF EXIST %1.res SET VRES="%~1.res"
:nores
ECHO Compiling "%~1.cpp"..........
cl.exe /c /Ox /W1 /EHsc /MT -D_WIN32_WINNT=0x502 "%~1.cpp"
ECHO Linking ................
link.exe /DLL /RELEASE /DEF:"%~1.def" /MACHINE:X64 /SUBSYSTEM:WINDOWS,5.02 "%~1.obj" %VRES% %2 %3 %4 %5 %6 %7 %8 %9 /OUT:"%~1.dll"
ECHO Finished!
IF EXIST "%~1.obj" del "%~1.obj"
IF EXIST %1.exp del "%~1.exp"
IF EXIST %1.def del "%~1.def"
GOTO done
:usage
ECHO **************************************************************
ECHO  Usage:  VS160D64.BAT MainFile  ExtraFile1 ExtraFile2 ExtraFile3
ECHO  Note:   ExtraFiles can be .libs, .res , .obj
ECHO       Use this batch file to easily create your DLL program
ECHO **************************************************************
:done
endlocal


the compiling and linking produce these messages

Code: [Select]

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.6.4
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Compiling "BCXPP.cpp"..........
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28806 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

BCXPP.cpp
Linking ................
Microsoft (R) Incremental Linker Version 14.26.28806.0
Copyright (C) Microsoft Corporation.  All rights reserved.

BCXPP.obj : warning LNK4197: export 'ProcessLine' specified multiple times; using first specification
   Creating library BCXPP.lib and object BCXPP.exp
BCXPP.exp : error LNK2001: unresolved external symbol _ProcessLine@4
BCXPP.dll : fatal error LNK1120: 1 unresolved externals


jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: Microsoft Compiled BCXPP.dll
« Reply #1 on: July 17, 2020, 01:15:43 PM »
Robert,
  I just use:
Quote
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64

:: CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat"x86_amd64
cl /LD "bcxpp.cpp"

Robert

  • Sr. Member
  • ****
  • Posts: 449
    • View Profile
Re: Microsoft Compiled BCXPP.dll
« Reply #2 on: July 17, 2020, 03:42:12 PM »
When this code

Code: [Select]

$DLL STDCALL
FUNCTION ProcessLine (Src$) AS LONG EXPORT
  IF Src$ = "DISPLAY MESSAGE" THEN Src$ = "PRINT " + ENC$("MAGIC HAPPENS!")
  FUNCTION = 1
END FUNCTION


is translated with a 64 bit BCX 7.5.0 and compiled with this batch file

Code: [Select]

setlocal
@rem Created with BldBat Version.4.1.2 for Microsoft Visual Studio 2019 X64 (STDCALL DLL)
@ECHO OFF
IF NOT EXIST %1.cpp GOTO usage
PUSHD "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\"
CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
POPD
IF EXIST %1.res GOTO res
IF NOT EXIST "res\%~1.rc" GOTO nores
ECHO Compiling resources.....
rc.exe /fo "%~1.res" /ires "res\%~1.rc"
:res
IF EXIST %1.res SET VRES="%~1.res"
:nores
ECHO Compiling "%~1.cpp"..........
cl.exe /c /Ox /W1 /EHsc /MT -D_WIN32_WINNT=0x502 "%~1.cpp"
ECHO Linking ................
link.exe /DLL /RELEASE /DEF:"%~1.def" /MACHINE:X64 /SUBSYSTEM:WINDOWS,5.02 "%~1.obj" %VRES% %2 %3 %4 %5 %6 %7 %8 %9 /OUT:"%~1.dll"
ECHO Finished!
IF EXIST "%~1.obj" del "%~1.obj"
IF EXIST %1.exp del "%~1.exp"
IF EXIST %1.def del "%~1.def"
GOTO done
:usage
ECHO **************************************************************
ECHO  Usage:  VS160D64.BAT MainFile  ExtraFile1 ExtraFile2 ExtraFile3
ECHO  Note:   ExtraFiles can be .libs, .res , .obj
ECHO       Use this batch file to easily create your DLL program
ECHO **************************************************************
:done
endlocal


the compiling and linking produce these messages

Code: [Select]

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.6.4
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x64'
Compiling "BCXPP.cpp"..........
Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28806 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

BCXPP.cpp
Linking ................
Microsoft (R) Incremental Linker Version 14.26.28806.0
Copyright (C) Microsoft Corporation.  All rights reserved.

BCXPP.obj : warning LNK4197: export 'ProcessLine' specified multiple times; using first specification
   Creating library BCXPP.lib and object BCXPP.exp
BCXPP.exp : error LNK2001: unresolved external symbol _ProcessLine@4
BCXPP.dll : fatal error LNK1120: 1 unresolved externals


When the BCXPP.bas file is translated a BCXPP.def file is created

Code: [Select]

LIBRARY "BCXPP"
EXPORTS
ProcessLine = _ProcessLine@4



This is the cause of the error when the batch file is run.

Removing the snippet

Code: [Select]

/DEF:"%~1.def"


from the batch file link command line allows the BCXPP.dll to be compiled successfully.

My solution is to change my batch files and when needed add the /DEF: flag.


MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 538
    • View Profile
Re: Microsoft Compiled BCXPP.dll
« Reply #3 on: July 17, 2020, 03:54:54 PM »

That was my solution too   ----   remove /DEF:"%~1.def"

One thing that I read in the past is that .def files are useful if you want maximum control over naming and ordinals but usually they are simply unnecessary.

Robert

  • Sr. Member
  • ****
  • Posts: 449
    • View Profile
Re: Microsoft Compiled BCXPP.dll
« Reply #4 on: July 17, 2020, 04:27:39 PM »

That was my solution too   ----   remove /DEF:"%~1.def"

One thing that I read in the past is that .def files are useful if you want maximum control over naming and ordinals but usually they are simply unnecessary.

I just read that .def files are not needed when the functions are typed __declspec(dllexport)  which BCX does with the C_EXPORT defines.

Pretty slick, I'd say!