Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Passing a string to an external DLL function in Alpha

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Passing a string to an external DLL function in Alpha

    I'm using A5v8. I'm trying to call a function in an external DLL. Here's the VBA code:

    Private Declare Function GetHardwareID Lib "HardwareID.dll" (ByVal bHDD As Boolean, ByVal bNIC As Boolean, ByVal bCPU As Boolean, ByVal bBIOS As Boolean, ByVal sRegCode As String) As String.

    Here's what I'm doing in Alpha:

    Code:
    ' returns string, takes 4 booleans, and a string
    declare HardwareID GetHardwareID CWWWWC
    ' xxxx-xxxx is the registration code for removing nag window 
    ' you pass the registration code and it does the call silently
    hdwid = GetHardwareID(0,0,1,1,"xxxx-xxxx")
    I have to pass the function our registration code which unlocks the full version of the DLL.

    The function call works fine, it returns the proper string, but I still get the nag screen. I have verified the registration code is good, the code works fine in VBA.

    I've looked over other examples on the board and tried passing the registration code as a character variable and also as a pointer to a string:

    Code:
    dim temp as p
    temp.sSerial = "xxxx-xxxx"
    hdwid = GetHardwareID(0,0,1,1,temp)
    Nothing I've tried so far has worked. According to the vendor's help file, this is how the function is declared:

    LPTSTR WINAPI GetHardwareID(
    BOOL bHdd,
    BOOL bNic,
    BOOL bCpu,
    BOOL bBios,
    LPCTSTR sRegCode
    );

    LPCTSTR is a Long Pointer Constant to a null-Terminated String. I also tried passing the serial as a Blob, no joy.

    I've already emailed the vendor, but have not heard back from them yet. Is there something obvious I'm missing about passing a string to an external function?

    Any help would be appreciated.

    Rick

    #2
    Re: Passing a string to an external DLL function in Alpha

    Rick,
    Have you tried running a vbs script directly in Alpha with the A5_run_vbscript() built-in function instead of converting a vb script to xbasic? Or even find a vbs script and then use sys_open() to run it?

    The A5_run_vbscript() function located here
    http://support.alphasoftware.com/alp...VBScript().htm
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________



    Comment


      #3
      Re: Passing a string to an external DLL function in Alpha

      Mike,

      Thanks for that suggestion, I had no idea that function existed.

      However, I don't think it will work for me because:
      1) according to what I read, you can't call DLL's from VBScript without an ActiveX control or a wrapper and 2) I can't retrieve a value from the script other than an error code without writing the value to an intermediate file or clipboard, which is what I'm trying to avoid by using the DLL in the first place.

      If you know any workarounds for those issues, I'd love to hear about them.

      Thanks,
      Rick

      Comment


        #4
        Re: Passing a string to an external DLL function in Alpha

        Hi Rick,

        Try the next code:

        Code:
        'declare a 1 kb buffer to recieve the returned text.
        declarestruct [COLOR=seagreen]udtBuffer[/COLOR] C1024[COLOR=red]varReadBuffer[/COLOR]
         
        'the api function to unlock the dll
        declare HardwareID GetHardwareID ([COLOR=seagreen]udtBuffer[/COLOR])WWWWC 'the wwww is correct
         
        dim LPCTSTR as {[COLOR=seagreen]udtBuffer[/COLOR]}
         
        LPCTSTR = GetHardwareID(0,0,1,1,"xxxx-xxxx")
         
        msgbox("Title",LPCTSTR.[COLOR=red]varReadBuffer[/COLOR])
        Last edited by Marcel Kollenaar; 09-18-2008, 01:13 PM. Reason: 'the wwww is correct bbbb is wrong
        Marcel

        I hear and I forget. I see and I remember. I do and I understand.
        ---- Confusius ----

        Comment


          #5
          Re: Passing a string to an external DLL function in Alpha

          Marcel,

          Thanks for that, but the return string isn't the problem, it's the "xxxx-xxxx" string that I'm trying to pass to the DLL. For some reason the DLL doesn't see it as a valid registration code, even though the code works properly in a VBA function.

          I already tried passing the registration code string as a pointer to a string and it didn't work.

          Any other ideas?

          Comment


            #6
            Re: Passing a string to an external DLL function in Alpha

            This is almost the same as:

            Code:
            dim temp as p
            temp.sSerial = "xxxx-xxxx"
            hdwid = GetHardwareID(0,0,1,1,temp)
            but the declarestruct is as low level as possible.

            Code:
            declarestruct udtBuffer C9license
            declare HardwareID GetHardwareID CWWWW(udtBuffer)
             
            dim Buffer as {udtBuffer}
            Buffer.license = "xxxx-xxxx"
             
            hdwid = GetHardwareID(0,0,1,1,Buffer)
            Last edited by Marcel Kollenaar; 09-18-2008, 01:48 PM. Reason: changed LPCTSTR into hdwid
            Marcel

            I hear and I forget. I see and I remember. I do and I understand.
            ---- Confusius ----

            Comment


              #7
              Re: Passing a string to an external DLL function in Alpha

              Marcel,

              Tried the udtBuffer code, but no go. It's weird, who would think passing a string to a DLL would be such a hassle?

              Comment


                #8
                Re: Passing a string to an external DLL function in Alpha

                I'm willing to show off my ignorance.

                Your original post states...

                LPCTSTR is a Long Pointer Constant to a null-Terminated String.
                I have no idea whether normal strings in Alpha are null-Terminated or not. How about trying appending a null (chr(0)) to your "xxxx-xxxx"?

                "xxxx-xxxx"+chr(0)
                There can be only one.

                Comment


                  #9
                  Re: Passing a string to an external DLL function in Alpha

                  Yes, Alpha 5 strings are null-terminated. I did try the chr(0) idea also, just in case with both a string type and a blob type, but it didn't work.

                  I'm sure the answer is ridiculously simple, but the vendor is non-responsive so I'm left to blunder around trying different things. Grrr.

                  Comment


                    #10
                    Re: Passing a string to an external DLL function in Alpha

                    MARCEL IS A GENIUS!

                    Thanks to some private emails back and forth, Marcel put me on the right track. To make this DLL work, you declare the function as:

                    Code:
                    declare HardwareID GetHardwareID CLLLLC
                    I was using CWWWWC. Apparently what the DLL expects for boolean values are 32-bit signed int Longs rather than 16-bit unsigned int 'W'.

                    So even though the 4 boolean parameters worked, it was screwing up the string boundary of the registration code.

                    I had to completely reboot in order to get Marcel's example working, though, so be aware that when experimenting with declare and DLL's, it never hurts to reboot.

                    I just want to say thanks again to everyone who contributed suggestions to this thread and especially Marcel for coming up with the solution. That kind of generosity exemplifies why the Alpha community is one of the best.

                    Rick

                    Comment


                      #11
                      Re: Passing a string to an external DLL function in Alpha

                      Hi Rick,

                      Originally posted by Rick Gerlach View Post
                      I had to completely reboot in order to get Marcel's example working, though, so be aware that when experimenting with declare and DLL's, it never hurts to reboot.
                      Constant rebooting of Alpha Five after changing DECLARE and DECLARESTRUCT and then restoring the development environment was the original development reason for the CSDA Code Utility for Alpha Five.

                      I estimated it was a minimum of 2 to 4 minutes per reboot shaved down to 30 seconds or less (plus a whole lot less typing!).
                      Regards,

                      Ira J. Perlow
                      Computer Systems Design


                      CSDA A5 Products
                      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                      CSDA Barcode Functions

                      CSDA Code Utility
                      CSDA Screen Capture


                      Comment


                        #12
                        Re: Passing a string to an external DLL function in Alpha

                        MARCEL IS A GENIUS!
                        No argument here! When it comes to anything regarding these dll/API conversions, Marcel sure seems to have the knack (and persistence!) in solving them.
                        Mike
                        __________________________________________
                        It is only when we forget all our learning that we begin to know.
                        It's not what you look at that matters, it's what you see.
                        Henry David Thoreau
                        __________________________________________



                        Comment

                        Working...
                        X