X0r hat geschrieben:Hm, ich denke ich werds wohl über ne DLL lösen.
Auch wenn Du die DLL-Version der VC++ Runtime nimmst,
mußt Du diese initialisieren, sonst kann es laut MSDN zu
einem "C Run-Time Error R6030" kommen:
MSDN hat geschrieben:CRT not initialized
This error occurs if you are using the CRT, but the CRT startup code was not executed. It is possible to get this error if the linker switch /ENTRY is used to override the default starting address, usually mainCRTStartup, wmainCRTStartup for a console EXE, WinMainCRTStartup or wWinMainCRTStartup for a Windows EXE, or _DllMainCRTStartup for a DLL.
Der obige Code war eh nicht korrekt und hätte nur Probleme gemacht.
Hier die neue Version:
Code: Alles auswählen
#PB_Compiler_Console = 0 ; set to 1 if you compile as console app
#USE_STATIC_C_LIBRARY = 1 ; 1 = static c library
; 0 = dynamic c library (DLL)
;>[ VC++ library include ]--------------------------------------------
CompilerIf #PB_Compiler_OS = #PB_OS_Windows
CompilerIf #PB_Compiler_Debugger
CompilerError "Important: Disable debugger!"
CompilerEndIf
;>[ VC++ library import ]-----------------------------------------
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
CompilerIf #USE_STATIC_C_LIBRARY = 0
ImportC "msvcrt.lib" ; msvcrt.lib = 32bit dynamic VC++ runtime library
CompilerElse
ImportC "libcmt.lib" ; libcmt.lib = 32bit static VC++ runtime library
CompilerEndIf
CompilerCase #PB_Processor_x64
CompilerIf #USE_STATIC_C_LIBRARY = 0
ImportC "msvcrt64.lib" ; msvcrt64.lib = 64bit dynamic VC++ runtime library (rename it)
CompilerElse
ImportC "libcmt64.lib" ; libcmt64.lib = 64bit static VC++ runtime library (rename it)
CompilerEndIf
CompilerEndSelect
isalpha.l(c.l)
WinMainCRTStartup() ; Windows
mainCRTStartup() ; Console
wWinMainCRTStartup() ; Windows, Unicode
wmainCRTStartup() ; Console, Unicode
DllMainCRTStartup() ; call this to init the C library in DLLs
EndImport
;>[ VC++ library init ]-------------------------------------------
CompilerIf #PB_Compiler_Unicode=0
CompilerIf #PB_Compiler_Console = 0
WinMainCRTStartup() ; init VC++ runtime library, Windows
CompilerElse
mainCRTStartup() ; init VC++ runtime library, Console
CompilerEndIf
CompilerElse
CompilerIf #PB_Compiler_Console = 0
wWinMainCRTStartup() ; init VC++ runtime library, Windows, Unicode
CompilerElse
wmainCRTStartup() ; init VC++ runtime library, Console, Unicode
CompilerEndIf
CompilerEndIf
!ret
CompilerSelect #PB_Compiler_Processor
CompilerCase #PB_Processor_x86
!public _main
!public _wmain
!public _wWinMain
!public _WinMain
!_main:
!_wmain:
!_wWinMain:
!_WinMain:
CompilerCase #PB_Processor_x64
!public main
!public wmain
!public wWinMain
!public WinMain
!main:
!wmain:
!wWinMain:
!WinMain:
CompilerEndSelect
CompilerElse
CompilerError "Error. VC++ library only supported on windows."
CompilerEndIf
;>[ VC++ library end ]------------------------------------------------
;
;-[ Main ]------------------------------------------------------------
;
; start of program
;
EnableExplicit
Procedure output()
Define i
For i = 0 To 255
Print( Str( isalpha(i) ) )
Next
PrintN("")
EndProcedure
If OpenConsole()
PrintN("output start")
output()
PrintN("output end")
PrintN("press <ENTER>")
Input()
CloseConsole()
EndIf
Du kannst zwischen der statischen und dynamischen (DLL) Version
mit der Konstante #USE_STATIC_C_LIBRARY wählen.
Unterstützt werden 32bit und 64bit Versionen der Libraries, allerdings
mußt Du die 64bit-Versionen umbenennen zu msvcrt64.lib & libcmt64.lib.
Beim kompilieren mit Unicode wird die Unicode-Version der
Initialisierungsfunktion aus der VC++ Library gewählt.
Wenn Du als Console-Programm kompilierst, muß die Konstante
#PB_Compiler_Console ganz am Anfang auf 1 gesetzt werden,
wenn Du als Windows-Programm kompilierst eben auf 0.
Für die DLL-Erstellung funktioniert dieser Code nicht, dafür muß
man über DllMainCRTStartup() wieder ganz anders rangehen.
Weiterhin ist sehr wichtig, daß der Startup-Code zum initialisieren
genau so dort bleibt und eigener PB-Code erst nach dem Marker
";-[ Main ]---------------------------------------------------------"
anfängt. Ab dort kannst Du dann aber ganz normal coden.
Durch das einbinden und initalisieren der VC++ Runtime Library
wird der Programmablauf geändert:
- 1. PB initialisiert libraries usw. in ASM
- 2. Die VC++ Runtime wird initialisiert.
- 3. Die VC++ Runtime springt eines der verschiedenen "main" Labels an
- 4. Der normale PB Code wird ausgeführt
- 5. PB räumt auf in ASM (library end functions usw.)
- 6. PB springt zurück in die VC++ Runtime Init Function
- 7. Die VC++ Runtime räumt auf
- 8. Das Programm wird beendet
Probier nochmal damit. Die VC++ Runtime Library wird so schön
in allen möglichen Variationen eingebunden (x86,x64,Unicode,statisch,dynamisch).
Daran sollte es imo nicht liegen, wenn Du noch Fehler bekommst.
EDIT:
Debugger muß aus sein! Der mag das wohl nicht,
wenn der Programmablauf geändert wird (verständlich).

'DisableDebugger' hilft da auch nicht.