I think we got it, thank you very very much!!
I'm still having a VB issue, but the function *IS* working, rather sweet and I learned a LOT today...went to a lot of VB "Guru's" today that could not answer this, and well, even one C++ guru....
Thanks,
Scott
------------------
Scott Turchin
Announcement
Collapse
No announcement yet.
Exporting Strings to VB
Collapse
X
-
OK This is the final of the VB_Function and the header from the other function, it still gives a Dr Watson but I will figure out how to call the VB portion and handle that when I get some time tonight, preciate your effort!!
Code:'You have To adjust you PBDLL-Function like this: Function VB_ParseEMailFile Alias "VB_ParseEmailFile" (ByRef FileSpec As String, _ ByRef psaInfoData As Dword, _ ByRef psaInfoQty As Dword, _ ByRef psaInfoProdName As Dword, _ ByRef psaInfoAmt As Dword, _ ByVal ArrayCount As Long) Export As Long '2/9/00 Local lower&,upper& Local vbArray As Dword '--convert pInfoData SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoData, 1) upper& = vbArrayUBound(psaInfoData, 1) vbArray = vbArrayFirstElem(psaInfoData) Dim pInfoData(lower& To upper&) As String At vbArray '--convert pInfoQty SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoQty, 1) upper& = vbArrayUBound(psaInfoQty, 1) vbArray = vbArrayFirstElem(psaInfoQty) Dim pInfoQty(lower& To upper&) As String At vbArray '--convert pInfoProdName SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoProdName, 1) upper& = vbArrayUBound(psaInfoProdName, 1) vbArray = vbArrayFirstElem(psaInfoProdName) Dim pInfoProdName(lower& To upper&) As String At vbArray '--convert pInfoAmt SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoAmt, 1) upper& = vbArrayUBound(psaInfoAmt, 1) vbArray = vbArrayFirstElem(psaInfoAmt) Dim pInfoAmt(lower& To upper&) As String At vbArray Function = ParseEmailfile(GetFileName(0),pInfoData(),pInfoQty(),pInfoProdName(),pInfoAmt(),ArrayCount) End Function Function ParseEmailFile Alias "ParseEmailFile" (FileSpec As String, _ pInfoData() As String,_ pInfoQty() As String, _ pInfoProdName() As String, _ pInfoAmt() As String,_ ArrayCount As Long) Export As Long 'Fill arrays and exit End Function
Scott Turchin
[This message has been edited by Scott Turchin (edited February 09, 2000).]
Leave a comment:
-
Yes, strings you put/change in the array is accessed from VB as
FithString$ = pInfoQty(5)
Forget this psaInfoAmt = @pInfoAmt()
You are passing your PBArrays ByRef and all changes in
ParseEmailFile(..) to this arrays will be propagated back
to VB_ParseEmailFile(..) and eventually back to your
VB-application...
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
OK Cool, but....when the data is returned from the PB Function to the VB function it has to go back out as psaInfoData for exmaple from pInfoData(), is that handled automatically or needs a pointer to return?
Thanks, I'm FINALLY getting a grasp on what is happening!
Learning is good...
Scott
------------------
Scott Turchin
Leave a comment:
-
Well,
to be safe you have to dim your array in VB.
You have to set the array-bounds.
Dim pInfoQty(10) as string
You dont have to prefill the array with data in VB
This is because you are querying the upper/lower bounds
of the safearray in your function!
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
OK Thanks, now I am CLOSERr to understanding what is happening, and i feel like I did when my daughter's compaq computer blew up and I *HAD* to buy the part from them...proprietary....hate that word!
But, so longas I know this, I can duplicate functions or make a callable function for VB with no problem..
OK The GetFile function you saw just calls an open file dialog box, that part works....
Now, once the function is complete, am I passing a pointer back to VB?? In other words:
Code:Function = ParseEmailfile(GetFileName(0),pInfoData(),pInfoQty(),pInfoProdName(),pInfoAmt(),ArrayCount) psaInfoAmt = @pInfoAmt()
Thanks Fred, yer awesome
------------------
Scott Turchin
[This message has been edited by Scott Turchin (edited February 09, 2000).]
Leave a comment:
-
Yes, you have to call two diffrent functions in your MAILP.DLL
From VB you use VB_ParseEMailFile(...)
From PB you use ParseEmailFile(...)
This because you need to know if it is a SAFEARRAY or a PBArray
that is passed to the function.
Your solution is correct (..not quite but close)
Code:Function VB_ParseEMailFile(......) ... ... ... Function = ParseEMailFile([b]FileSpec[/b],pInfoQty(),....) End function
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
Your assumption is correct, I am dimming everything in VB, sending an array to PB, if my PB code redims it, it's wrong (THis is where the confusion lies)...
However, the arrays are empty upon entering PB, PB will fill them, at which point a Dr Watson/GPF occurs...
Scott
------------------
Scott Turchin
Leave a comment:
-
I have to add also...
My example is based on VB sending you arrays with data
that you will use in your function.
That is: You dim the array in VB to be large enough to
hold elements you return.
If you want to redim the array and fill it with new data
you really have to take a close look in Win32Api-help.
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
The variables return string, but the FUNCTION itself will return a long... You are on track, but I am not understanding this 100%....Almost, but not quite...
Do I understand correct to say that VB_functionname is lining up and converting the variables for use by PB for VB and th en the original function is called from WITHIN the DLL for VB?? Otherwise leave the original function intact?
If so...is this way off base?
Code:'You have To adjust you PBDLL-Function like this: Function VB_ParseEMailFile (ByRef FileSpec As String, _ ByRef psaInfoData As Dword, _ ByRef psaInfoQty As Dword, _ ByRef psaInfoProdName As Dword, _ ByRef psaInfoAmt As Dword, _ ByVal ArrayCount As Long) Export As Long '2/9/00 Local lower&,upper& Local vbArray As Dword '--convert pInfoData SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoData, 1) upper& = vbArrayUBound(psaInfoData, 1) vbArray = vbArrayFirstElem(psaInfoData) Dim pInfoData(lower& To upper&) As String At vbArray '--convert pInfoQty SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoQty, 1) upper& = vbArrayUBound(psaInfoQty, 1) vbArray = vbArrayFirstElem(psaInfoQty) Dim pInfoQty(lower& To upper&) As String At vbArray '--convert pInfoProdName SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoProdName, 1) upper& = vbArrayUBound(psaInfoProdName, 1) vbArray = vbArrayFirstElem(psaInfoProdName) Dim pInfoProdName(lower& To upper&) As String At vbArray '--convert pInfoAmt SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoAmt, 1) upper& = vbArrayUBound(psaInfoAmt, 1) vbArray = vbArrayFirstElem(psaInfoAmt) Dim pInfoAmt(lower& To upper&) As String At vbArray Function = ParseEmailfile(GetFileName(0),pInfoData(),pInfoQty(),pInfoProdName(),pInfoAmt(),ArrayCount) End Function '----------------------------------------------------------------------------
[This message has been edited by Scott Turchin (edited February 09, 2000).]
Leave a comment:
-
My function is now sending a string back?
It used to send a long indicating success or failure...
I have a function that exports a string array, the function returns a long,
Code:Public pInfoQty() As String Public pInfoProdName() As String Public pInfoAmt() As String Public ArrayCount As Long Global St As String Public Declare Function PARSEEMAILFILE Lib "MAILP.DLL" _ (FileSpec As String,pInfoQty() As String,pInfoProdName() As String, _ pInfoAmt() As String, ArrayCount As Long)[b]As String[/b]
I dont know which is correct. I supposed it was the declaration...
If you want to return a long, Fine do that.There are nothing forcing you to return a string.
Also, when I CALL the function, I'm sending the actual ARRAY from VB or a DWORD??? I'm confused now..
to the variable as a pointer (long/DWord)
In this case you pass a pointer to a SAFEARRAYDESCRIPTOR
You probably noticed that I renamed your PB-function to VB_ParseEMailFile.
This because you have to convert the SAFEARRAY to PowerBasic-Arrays when called from VB/VC++
Keep your original function to be called from PowerBasic.
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
[This message has been edited by Fred Oxenby (edited February 09, 2000).]
Leave a comment:
-
So far so good, I'm with you, and it's compiling with one exception...
My function is now sending a string back?
It used to send a long indicating success or failure...
I have an idea it has to do it as string to return the values, but I'm confused about that.
Also, when I CALL the function, I'm sending the actual ARRAY from VB or a DWORD??? I'm confused now..
thanks!!
Scott
------------------
Scott Turchin
[This message has been edited by Scott Turchin (edited February 09, 2000).]
Leave a comment:
-
If you pass from VB (to a DLL) a StringArray with empty parenthesis
=> MyStrings() VB is actually passing a SAFEARRAY (array of pointers to String)
Your code does not indicate if ArrayCount should be ByVal or ByRef.
Code:You have to adjust you PBDLL-function like this: #Include: "VBAPI32.INC" 'You will find it in PBDLL60\SAMPLE\VB32 Dir Function VB_ParseEMailFile (ByRef FileSpec As String, _ ByRef psaInfoQty As DWord, _ ByRef psaInfoProdName As DWord, _ ByRef psaInfoAmt As DWord, _ ByVal ArrayCount As Long) EXPORT As String LOCAL lower&,upper& LOCAL vbArray AS DWORD '--convert pInfoQty SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoQty, 1) upper& = vbArrayUBound(psaInfoQty, 1) vbArray = vbArrayFirstElem(psaInfoQty) [b]DIM pInfoQty(lower& to upper&) AS STRING AT vbArray[/b] '--convert pInfoProdName SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoProdName, 1) upper& = vbArrayUBound(psaInfoProdName, 1) vbArray = vbArrayFirstElem(psaInfoProdName) [b]DIM pInfoProdName(lower& to upper&) AS STRING AT vbArray[/b] '--convert pInfoProdAmt SafeArray To PB-Array-------- lower& = vbArrayLBound(psaInfoAmt, 1) upper& = vbArrayUBound(psaInfoAmt, 1) vbArray = vbArrayFirstElem(psaInfoAmt) [b]DIM pInfoAmt(lower& to upper&) AS STRING AT vbArray[/b] --Your Code using pInfoQty(),pInfoProdName(),pInfoAmt() stringArrays-- --Etc Etc-- End function
Code:Public Declare Function PARSEEMAILFILE Lib "MAILP.DLL" _ (ByRef FileSpec As String, _ pInfoQty() As String, _ pInfoProdName() As String, _ pInfoAmt() As String, ByVal ArrayCount As Long) As String
[This message has been edited by Fred Oxenby (edited February 09, 2000).]
Leave a comment:
-
Thanks Fred,
I knew the SafeArray was going to come into play somewhere.
The Help file also shows using pointers, but I want to pass the array, it's not that big and I don't have quite enough experience with pointers right now (Time crunch on this project)...
Do you have a sample of how to do that in VB?
------------------
Scott Turchin
Leave a comment:
-
Have a look in PB/DLL help Appendix B
Visual Basic stores string data in Unicode format.
When you pass a string from Visual Basic to PowerBASIC,
VB will convert the string to ANSI. However, if you pass only
the first element of the string array to PowerBASIC, only that
element will be converted.
All of the remaining elements in the array are still in Unicode format.
To access a string array or UDT array that has strings, you need
to have Visual Basic pass the SafeArray handle to the array.
By passing the array handle, you force Visual Basic to convert
all of the strings from Unicode to ANSI format.
------------------
Fred
mailto:[email protected][email protected]</A>
http://www.oxenby.se
Leave a comment:
-
Exporting Strings to VB
I have a function that exports a string array, the function returns a long, I realize this is a VB question but perhaps someone may know the answer (I hope it's not a vbstring thing)...
So lets say pInfoData() is dimmed 1 to 5 as STRING, all 5 elements fill up with strings and vb calls it as such, and without even CALLING the function, just having an edit box on the form, I get a GPF in my DLL, the sample PB/DLL executable that calls this has ZERO problems...
Code:VB: Public pInfoQty() As String Public pInfoProdName() As String Public pInfoAmt() As String Public ArrayCount As Long Global St As String Public Declare Function PARSEEMAILFILE Lib "MAILP.DLL" (FileSpec As String, _ pInfoQty() As String, _ pInfoProdName() As String, _ pInfoAmt() As String, ArrayCount As Long) As String
-------------
Scott Turchin
Tags: None
Leave a comment: