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

Example DLL translation from VBA into Xbasic

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

  • Example DLL translation from VBA into Xbasic

    Hi,

    I'm i the mood for code translation and espcially from VB(A) into Xbasic with an emphasis on DLL's.

    Selwyn Rabins wrote in 2002 a piece of Xbasic code for the sys_shell_wait() routine. Now I found the counter part of it in Visual Basic. It's nice to have two pieces of "heavy" code and see the translation of it (see attachment). We can learn a lot of it. It will help you a lot in translating VB code which calls dll's. There is a tremendous amount of VB code ready for use in Xbasic. Ehhh, at least if you can use it.

    Take also a look at the Win32s Programmer's Reference.hlp (API) for the specific functions and structures used and you see a translation-triangle C-VB-Xbasic. Don't forget to read the very good information on "Pie Charts in Alpha Five" by Dr. Peter Wayne http://learnalpha.com/PieCharts/PieCharts.htm.

    Regards,

    Marcel
    Marcel

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

  • #2
    RE: Example DLL translation from VBA into Xbasic

    Marcel,
    Thank you, that's very valuable. You should also know that A5 lets you create user-defined types, just like VB, so that it becomes easier to modify VB code. Your code could be compressed like this, and I believe this is clearer, and more similar to VB:
    Code:
    command="Notepad.exe"
    sys_shell_wait(command,.t.)
    ui_msg_box("Notepad","was closed")
    end 
    
    FUNCTION sys_shell_wait AS V (command_line AS C, show_window AS L )
    
    ' declare types and hooks to WinAPI
    
    type startupinfo 
    	cb as Integer
    	lpReserved as C
    	lpDesktop as C
    	lpTitle AS C
    	dwX AS Integer
    	dwY AS Integer
    	dwXSize AS Integer
    	dwYSize AS Integer
    	dwXCountChars AS Integer 
    	dwYCountChars AS Integer
    	dwFillAttribute AS Integer
    	dwFlags AS Integer
    	wShowWindow AS Integer
    	cbReserved2 AS Integer
    	lpReserved2 AS Integer
    	hStdInput AS Integer
    	StdOutput AS Integer
    	hStdError AS Integer
    end type
    
    type process_information
    	hprocess as Integer
    	hThread as Integer
    	dwProcessID as Integer
    	dwThreadID as Integer
    end type 
    
    ' hooks to WinAPI
    declare KERNEL32 WaitForSingleObject LLL
    declare KERNEL32 CreateProcessA LLCLLLLLL(STARTUPINFO)(PROCESS_INFORMATION)
    declare KERNEL32 CloseHandle LL
    
    appExec(command_line, show_window)
    END FUNCTION
    
    FUNCTION appExec AS V (commandLine AS C, show_window AS L )
    CONSTANT NORMAL_PRIORITY_CLASS = hex_to_dec("20")	
    CONSTANT INFINITE = hex_to_dec("FFFFFFFF")
    
    dim start as {startupinfo}
    dim proc as {process_information}
    Dim nMilliseconds As N
    
    nMilliseconds = INFINITE
    IF show_window
    	Start.dwFlags = 4
    	Start.wShowWindow = 1
    ELSE
    	Start.dwFlags = 1
    	Start.wShowWindow = 0
    END IF
    
    CreateProcessA(0,CommandLine, 0, 0, 1, NORMAL_PRIORITY_CLASS, 0, 0, Start, proc)
    WaitForSingleObject(proc.hProcess, nMilliseconds)
    CloseHandle(proc.hThread)
    
    END FUNCTION
    There's also an error, I think, in the VB code that you provide. The CreateProcessA declaration takes a long as its first parameterm, followed by a string. So comparing Lissauer's code with yours (or Selwyn's, I'm not sure whose) doesn't work properly because Lissauer is calling CreateProcessA with the wrong parameter list. At least that's what the Microsoft knowledge base indicates in their description of using CreateProcessA.

    Comment


    • #3
      RE: Example DLL translation from VBA into Xbasic

      Hi Peter:

      This is great. Hats off to you and Marcel for these examples. I was planning to test Marcel's sys_shell_wait this weekend since I was never able to get Selwyn's original to work for some reason.

      Anyhow, the one you posted works perfectly including - and for me this is a real biggie - with CMD files such as copying the contents of a big folder or whatever else one might do in a dos window.

      Finian
      Finian

      Comment


      • #4
        RE: Example DLL translation from VBA into Xbasic

        Hi Peter,

        First, let me thank you very much for this compressed example you provided here. It's a master piece in my opinion. You gave me with your reply the answer at a question I just wanted to ask. It's about the use of DECLARESTRUCT and TYPE...END TYPE. I was just doing the splits.
        The people of Alpha Five told me to use the TYPE..END TYPE construction, however I never managed to get it to work in that way. Therefore I kept using the old DECLARESTRUCTs.

        With your information I start changing my code.

        About the fact that there could be an error in the VB code, yes it's possible. I didn't run this code, I used it only for comparison and I was in the middle of a study of it. I would probably overlooked the error ;-)

        Let me be clear about the source of the code. This isn't mine. The Xbasic code is written by Selwyn and the VB code is Lissauers and I found it by accidental on a VB site.

        Peter you helped me a lot.

        Regards,

        Marcel
        Marcel

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

        Comment


        • #5
          RE: Example DLL translation from VBA into Xbasic

          Finnian, what would the syntax be for copying the contents of
          c:\alpha\newha\Practice Before Multiple States\*.*
          to
          c:\alpha\newha\test33\*.*
          Cole Custom Programming - Terrell, Texas
          972 524 8714
          martin_w_cole@msn.com

          ____________________
          "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

          Comment


          • #6
            RE: Example DLL translation from VBA into Xbasic

            Martin:


            xcopy "c:\alpha\newha\Practice Before Multiple States\*.*"
            "c:\alpha\newha\test33\*.*" /E /Y

            On one line should do it. Iy will copy all files and folders and overwrite existing files without a prompt.

            Finian
            Finian

            Comment


            • #7
              RE: Example DLL translation from VBA into Xbasic

              Finnian, I meant using the sys_shell_wait()

              otherwise I just use batch files

              I was referring to what you mentioned:

              Anyhow, the one you posted works perfectly including - and for me this is a real biggie - with CMD files such as copying the contents of a big folder or whatever else one might do in a dos window.

              I can see the obvious benefits of this function when you want to stop processing until notepad or word or excel was closed, but for issuing other dos commands I can't get the syntax correct, as it apparently all has to be enclosed in quotes.

              for example, the following works (where all words are 8 or fewer characters in length):
              sys_shell_wait("xcopy c:\alpha\newha\test33\*.* c:\alpha\newha\test34\*.* /E /Y",.t.)

              whereas the following won't:
              sys_shell_wait("xcopy c:\alpha\newha\Practice Before Multiple States\*.* c:\alpha\newha\test34\*.* /E /Y",.t.)

              I was wondering how to write the second one.
              Cole Custom Programming - Terrell, Texas
              972 524 8714
              martin_w_cole@msn.com

              ____________________
              "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

              Comment


              • #8
                RE: Example DLL translation from VBA into Xbasic

                Martin,

                Have you tried single quotes around the paths with spaces in them?

                I've never tried this but I wonder if you sys_shell would accept a path in a variable. This would be worth knowing.

                Bill
                Bill Hanigsberg

                Comment


                • #9
                  RE: Example DLL translation from VBA into Xbasic

                  thanks Bill - yes I tried several possibilities, but can't get it to work.

                  usually, I do this in bat files, and use sys_shell to call them
                  Cole Custom Programming - Terrell, Texas
                  972 524 8714
                  martin_w_cole@msn.com

                  ____________________
                  "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                  Comment


                  • #10
                    RE: Example DLL translation from VBA into Xbasic

                    try this, Martin:
                    "pre"
                    sys_shell_wait("xcopy c:\alpha\newha\Practic~\*.* c:\alpha\newha\test34\*.* /E /Y",.t.) "/pre"

                    Comment


                    • #11
                      RE: Example DLL translation from VBA into Xbasic

                      sorry, forget to check the "use html" box:
                      Code:
                      sys_shell_wait("xcopy c:\alpha\newha\Practic~\*.* c:\alpha\newha\test34\*.* /E /Y",.t.)

                      Comment


                      • #12
                        RE: Example DLL translation from VBA into Xbasic

                        Martin:

                        Duh! Sorry.

                        I use this stuff in our upgrade application. I need to get the upgrade path and source files path from the user. I then create batch (cmd) files in xbasic to run the various processes. This is where sys_shell_wait will be a great simplifier. I think sys_shell_wait is built in to V6 but all my stuff is still in V5.

                        Anyway, I created a cmd file in Textpad called "copyfiles.cmd". In my test it has just one line:
                        xcopy "C:\OSOM Data\OMSCompV5\*.*" "C:\OSOM Data\temp\*.*" /E /Y

                        I used Peter's script pretty much as is:

                        command="C:\OSOM Data\OMSCompv5\copyfiles.cmd"
                        sys_shell_wait(command,.F.)
                        ui_msg_box("","Copyfiles was closed")
                        end

                        When run, this copies the files with no window showing.

                        Finian

                        with the command lines. Sometimes they are just one line
                        Finian

                        Comment


                        • #13
                          RE: Example DLL translation from VBA into Xbasic

                          Thanks to you both.
                          Peter, it doesn't work.
                          The solution may be to have single word, max 8 character length folder names
                          Cole Custom Programming - Terrell, Texas
                          972 524 8714
                          martin_w_cole@msn.com

                          ____________________
                          "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                          Comment


                          • #14
                            RE: Example DLL translation from VBA into Xbasic

                            Martin:

                            In the cmd files I always enclose the path to the files within quotes, whether they contain spaces or not and regardless of the length. This seems to work fine.

                            Finian
                            Finian

                            Comment


                            • #15
                              RE: Example DLL translation from VBA into Xbasic

                              Marcel,
                              Maybe you would like to try your hand at something that has stumped me since yesterday. I want to change the display resolution from within A5. Here is what I have done so far, but it doesn't work properly:

                              Code:
                              declarestruct charbuf C32charbuf
                              declarestruct charbufx C32charbufx
                              
                              type DEVMODE
                              dmDeviceName as charbuf
                              dmSpecVersion as Integer
                              dmDriverVersion as Integer
                              dmSize as Integer
                              dmDriverExtra as Integer
                              dmFields as Integer
                              dmOrientation as Integer
                              dmPaperSize as Integer
                              dmPaperWidth as Integer
                              dmScale as Integer
                              dmCopies as Integer
                              dmDefaultSource as Integer
                              dmPrintQuality as Integer
                              dmColor as Integer
                              dmDuplex as Integer
                              dmYResolution as Integer
                              dmTTOption as Integer
                              dmCollate as Integer
                              dmFormName as charbufx 
                              dmLogPixels as Integer
                              dmBitsPerPel as Integer
                              dmPelsWidth as Integer
                              dmPelsHeight as Integer
                              dmDisplayFlags as Integer
                              dmDisplayFrequency as Integer
                              end type 
                              
                              
                              declare USER32 EnumDisplaySettings@EnumDisplaySettingsA LLL(DEVMODE) 
                              declare USER32 ChangeDisplaySettings@ChangeDisplaySettingsA L(DEVMODE)L
                              
                              change_res(800, 600)
                              end
                              
                              function change_res(width as n, height as n)
                              	CONSTANT DM_PELSWIDTH = hex_to_dec("80000")
                              	constant DM_PELSHEIGHT = hex_to_dec("100000")
                              	
                              	dim DevM as {DEVMODE}
                              
                              	'dim displaymodes[100] as c
                              	
                              	dim disp as n
                              	disp=1
                              	i=0
                              	while disp>0 '.and. i
                              		disp= EnumDisplaySettings(0,i,DevM)
                              		i=i+1
                              		'displaymodes[i]=property_to_string(DevM)
                              	end while
                              	'for j=1 to i
                              	'	ui_msg_box(""+(j-1),displaymodes[j])
                              	'next	
                              	DevM.dmFields = DM_PELSWIDTH .or. DM_PELSHEIGHT
                              	DevM.dmPelsWidth = width
                              	DevM.dmPelsHeight = height
                              	b = ChangeDisplaySettings(DevM, 0)
                              	'ui_msg_box("b",""+b)
                              end function
                              If you uncomment the commented sections you wll see that EnumDisplaySettings does not return all properties--particularly, the BitsPerPel (PerPixel) is zero. So I'm clearly doing something wrong in the calling convention.

                              Comment

                              Working...
                              X