Page 1 of 1

Delphi/C++ specific source conversion [SOLVED]

Posted: Sat Oct 29, 2016 2:41 pm
by LiK137
Hi,
I'm stacked in one piece of Delphi (C++ source also exists and both working) code and need some advice.

Code: Select all

;C++ 
;int CodexEnum(wchar_t*** CodexList, int* CodexCount);


;Delphi
;function CodexEnum(CodexList: PWideChar; CodexCount: PInteger): integer; cdecl; external 'codexdk.dll';
;wchar_t** CodexList; 
;int CodexCount; 
 
;CodexInitEnum(); 
;if (CodexEnum(&CodexList, &CodexCount)==stat_OK) 
;for (int i=0; i<CodexCount; i++)  
;    wprintf(L"Codex: %s\n", CodexList[i]); 
;    printf("%d Codex(s) found.\n", CodexCount); 




;PB
Prototype.l CodexEnum(CodexList.l, CodexCount.l): CodexEnum.CodexEnum = GetFunction(0, "CodexEnum")

Dim CodexList.s(255)
Define CodexCount.i

CodexInitEnum()
if (CodexEnum(@CodexList(), @CodexCount)=#stat_OK)
  Debug "CodexCount: "+Str(CodexCount.i)
  For i = 0 To CodexCount-1
    Debug "List:"+Str(i)+"  |  "+CodexList(i)
  Next
EndIf
and PB code that I am wrestling several days only shows random 2-3 char nontext symbols which doesn't look like valid codec name.


Delphi code works and give this list but in purebasic I can't make it work.

ThanQ very much in advance

Re: Delphi/C++ specific source conversion

Posted: Sat Oct 29, 2016 2:56 pm
by acreis
Please post the non working PB code and we'll try to fix it!

Re: Delphi/C++ specific source conversion

Posted: Sat Oct 29, 2016 3:05 pm
by LiK137
ThanQ very much.
For that reason I have to share huge dll which is 25Mb

Code: Select all

Prototype.l CodexEnum(CodexList.l, CodexCount.l): CodexEnum.CodexEnum = GetFunction(0, "CodexEnum")

Dim CodexList.s(255)
Define CodexCount.i

CodexInitEnum()
if (CodexEnum(@CodexList(), @CodexCount)=#stat_OK)
  Debug "CodexCount: "+Str(CodexCount.i)
  For i = 0 To CodexCount-1
    Debug "List:"+Str(i)+"  |  "+CodexList(i)
  Next
EndIf
CodexCount is returned correctly but not list.
I want to understand how to translate below piece of code to PB

Code: Select all

;C++ 
int CodexEnum(wchar_t*** CodexList, int* CodexCount);
wchar_t ** CodexList;

or

;Delphi
function CodexEnum(CodexList: PWideChar; CodexCount: PInteger): integer; cdecl; external 'codexdk.dll';
wchar_t** CodexList; 

Re: Delphi/C++ specific source conversion

Posted: Sun Oct 30, 2016 10:43 am
by acreis
Lets try:

Code: Select all

;First try

EnableExplicit

#stat_OK = 0
Define i

Prototype.l CodexInitEnum()
Prototype.l CodexEnum(*lpCodexList, CodexCount.l)
Define CodexEnum.CodexEnum = GetFunction(0, "CodexEnum")
Define CodexInitEnum.CodexInitEnum = GetFunction(0, "CodexInitEnum")

Define CodexList
Define CodexCount.l

CodexInitEnum()

If (CodexEnum(@CodexList, @CodexCount)=#stat_OK)
  Debug "CodexCount: "+Str(CodexCount)
  For i = 0 To CodexCount-1
    Debug "List:"+Str(i)+"  |  "+ PeekS(CodexList)
    CodexList + SizeOf(Integer)
  Next
EndIf

Re: Delphi/C++ specific source conversion

Posted: Sun Oct 30, 2016 3:38 pm
by acreis
Second Try

Code: Select all

;Second try

EnableExplicit

#stat_OK = 0
Define i

Prototype.l CodexInitEnum()
Prototype.l CodexEnum(*lpCodexList, CodexCount.l)
Define CodexEnum.CodexEnum = GetFunction(0, "CodexEnum")
Define CodexInitEnum.CodexInitEnum = GetFunction(0, "CodexInitEnum")

Define CodexList
Define CodexCount.l

CodexInitEnum()

If (CodexEnum(@CodexList, @CodexCount)=#stat_OK)
  Debug "CodexCount: "+Str(CodexCount)
  For i = 0 To CodexCount-1
    Debug "List:"+Str(i)+"  |  "+ PeekS(PeekI(CodexList))
    CodexList + SizeOf(Integer)
  Next
EndIf

Re: Delphi/C++ specific source conversion

Posted: Sun Oct 30, 2016 7:54 pm
by LiK137
ThanQ acreis very much,
The problem has very stupid solution by moving to previous version of SDK.
Your both solution was correct and running but in previous version which is also OK for me. I reported Version Bug, Thanx again