-
Apr 17th, 2024, 10:09 PM
#1
Thread Starter
Fanatic Member
-
Apr 18th, 2024, 05:05 AM
#2
Re: VBA-RapidOCR how can i changed to vb6?
 Originally Posted by xxdoc123
If VarType(P(i)) = vbString Then P(i) = StrConv(P(i), vbFromUnicode): V(i) = StrPtr(P(i))
"vbFromUnicode" converts a string into a byte array so there is no "StrPtr" afterwards. Try an explicit byte array instead but if there are any Unicode characters in the string they will be lost when calling StrConv.
Code:
Dim ByteArray() As Byte
If VarType(P(i)) = vbString Then
ByteArray = StrConv(P(i), vbFromUnicode)
VType(i) = vbLong
VPtr(i) = VarPtr(ByteArray(0))
End If
Last edited by VanGoghGaming; Apr 18th, 2024 at 06:33 AM.
-
Apr 18th, 2024, 07:59 AM
#3
Re: VBA-RapidOCR how can i changed to vb6?
 Originally Posted by xxdoc123
how can fixed
https://github.com/DanysysTeam/VBA-RapidOCR
i download this zip about ocr for vba
but if run to this
Code:
'https://www.vbforums.com/showthread.php?789217-C-DLL-to-VB6&p=5505940&viewfull=1#post5505940 - Schmidt
Private Function cdeclCallA(sDll As String, _
sFunc As String, _
ByVal RetType As VbVarType, _
ParamArray P() As Variant) As Variant
Dim i As Long, pFunc As LongPtr, V() As Variant, HRes As Long
V = P 'make a copy of the params, to prevent problems with VT_Byref-Members in the ParamArray
For i = 0 To UBound(V)
If VarType(P(i)) = vbString Then P(i) = StrConv(P(i), vbFromUnicode): V(i) = StrPtr(P(i))
VType(i) = VarType(V(i))
VPtr(i) = VarPtr(V(i))
Next i
pFunc = GetFuncPtr(sDll, sFunc)
HRes = DispCallFunc(0, pFunc, CC_CDECL, RetType, i, VarPtr(VType(0)), VarPtr(VPtr(0)), cdeclCallA)
For i = 0 To UBound(P) 'back-conversion of the ANSI-String-Results
If VarType(P(i)) = vbString Then P(i) = StrConv(P(i), vbUnicode)
Next i
If HRes Then Err.Raise HRes
End Function
HTML Code:
HRes = DispCallFunc(0, pFunc, CC_CDECL, RetType, i, VarPtr(VType(0)), VarPtr(VPtr(0)), cdeclCallA) ----- crashed
VBA-RapidOCR-main.zip
thanks
Best would be to ask in the github repo's Issues.
cheers,
</wqw>
-
Apr 18th, 2024, 12:16 PM
#4
Re: VBA-RapidOCR how can i changed to vb6?
 Originally Posted by wqweto
Best would be to ask in the github repo's Issues.
Yep.
I also don't think, that the issue is with the helper-function itself (cdeclCallA)...
It might be more an issue with "feeding it the right, correct Params"
(especially in its 64Bit-adaption within the VBA-Code-Project).
@VanGoghGaming
... StrConv(..., vbFromUnicode) does not return a ByteArray-Type - but a normal BString-type instead (just filled with "non-wide" chars).
Here is a code-line for your Immediate-Window:
?TypeName(StrConv("abc", vbFromUnicode))
The fact that the below line works:
ByteArray = <any BString, or BString-returning function>
... is due to another implicit conversion under the covers - backed by these APIs in all likelihood:
https://learn.microsoft.com/en-us/pr...sion-functions
Olaf
Last edited by Schmidt; Apr 18th, 2024 at 12:23 PM.
-
Apr 18th, 2024, 05:19 PM
#5
Re: VBA-RapidOCR how can i changed to vb6?
Hmm yeah good one, I've only ever used "vbFromUnicode" in the context of byte arrays so it never occurred to me that another conversion was being done behind the scene. I've tried the functions you mentioned in that link:
Code:
Private Declare Function BstrFromVector Lib "oleaut32" (ByVal pSA As Long, ByVal pBSTR As Long) As Long
Private Declare Function VectorFromBstr Lib "oleaut32" (ByVal pBSTR As Long, ppSA As Long) As Long
BstrFromVector works fine as it is but I couldn't get VectorFromBstr to work. It does seem to return a valid SAFEARRAY pointer but the array is empty (cElements is zero). What am I missing there?
-
Apr 18th, 2024, 05:30 PM
#6
Re: VBA-RapidOCR how can i changed to vb6?
 Originally Posted by VanGoghGaming
Code:
Private Declare Function BstrFromVector Lib "oleaut32" (ByVal pSA As Long, ByVal pBSTR As Long) As Long
Private Declare Function VectorFromBstr Lib "oleaut32" (ByVal pBSTR As Long, ppSA As Long) As Long
BstrFromVector works fine as it is but I couldn't get VectorFromBstr to work. It does seem to return a valid SAFEARRAY pointer but the array is empty (cElements is zero). What am I missing there?
Probably "one level of dereferencing"...
With the following, quite simple change in the Declare, I got it to work properly:
Code:
Private Declare Function VectorFromBstr Lib "oleaut32" (ByVal pBSTR As Long, B() As Byte) As Long
Private Sub Form_Load()
Dim B() As Byte
Debug.Print VectorFromBstr(StrPtr(StrConv("abc", vbFromUnicode)), B)
Debug.Print UBound(B), B(0), B(1), B(2)
End Sub
Olaf
-
Apr 18th, 2024, 06:34 PM
#7
Thread Starter
Fanatic Member
Re: VBA-RapidOCR how can i changed to vb6?
Because I don't know the reason for the mistake. Perhaps there are significant differences between VBA and VB6. I hope to switch to running VB6?
Last edited by xxdoc123; Apr 19th, 2024 at 02:45 AM.
-
Apr 19th, 2024, 02:46 AM
#8
Thread Starter
Fanatic Member
Re: VBA-RapidOCR how can i changed to vb6?
A lot of times I only have access to a limited amount of new knowledge about VB6 in this forum. I'm not very familiar with VBA.
-
Apr 29th, 2024, 11:06 PM
#9
Thread Starter
Fanatic Member
Re: VBA-RapidOCR how can i changed to vb6?
Because of the network block, I have an error downloading the file from github. Caused me to test unsuccessfully, now I download the full program test and there is no problem
-
Apr 29th, 2024, 11:07 PM
#10
Thread Starter
Fanatic Member
Re: VBA-RapidOCR how can i changed to vb6?
Fortunately, this forum is not blocked. Long live freedom
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|