Announcement

Collapse
No announcement yet.

Baffled, Asciiz stuff

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

  • Baffled, Asciiz stuff

    I'm totally baffled.
    I've got this great VC++ DLL that does ActiveX modifications to IIS's virtual directories.

    This works great:
    szName as asciiz * 256
    szPath as asciiz * 256
    szName = "PBTEST2"
    szPath = "D:\TNGMP3"
    lResult = CreateVirtualRoot(szName,szPath,519,1,4)


    Works great, creates a path!

    This does not work:

    Global ScriptDir as String
    Global InstallDir as String

    ScriptDir = "/mp3" 'Read from an INI file
    InstallDir = "D:\TNGMP3" 'Read from registry
    szName = ScriptDir
    szPath = InstallDir
    lResult = CreateVirtualRoot(szName,szPath,519,1,4)

    '
    WHy is that? I've seen WEIRD things like this before, where passing the string to an Asciiz DOES pass (I can do a Msgbox and validate that!) but it won't work in the function....


    It's so close too, almost there.....


    Scott

    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    If I do a GetLastError it comes back as 1008, Privilege required.

    SO I do a Getprivilege for "System" since there doesn't seem to be a custom one for IIS.

    But agian the sample above it works just fine without doing that


    Scott

    ------------------
    Scott
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


    • #3
      Scott, have you had success when you assign szName = "/mp3" instead of using the value from the INI file?

      Do you have the source for the DLL?

      Comment


      • #4
        Scott --

        Are you certain that the strings from the INI file and registry are "clean", i.e. that they do not contain extra characters like $CR or $LF?

        Does it work if you use "mp3" instead of "/mp3"?

        -- Eric

        ------------------
        Perfect Sync Development Tools
        Perfect Sync Web Site
        Contact Us: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment


        • #5
          I would belive that you are handling a path with embedded space.
          There are a api in Shlwapi.dll that handle this kind of problem
          Code:
            BOOL PathMakePretty(LPTSTR lpPath);

          ------------------
          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Fred
          mailto:[email protected][email protected]</A>
          http://www.oxenby.se

          Comment


          • #6
            if I manually feed it the path /mp3 and D:\TNGMP3 it works fine.
            Those are the values read from the INI file too, I tried TRIM and whatnot...

            I'll give that API a shot......

            ------------------
            Scott
            Scott Turchin
            MCSE, MCP+I
            http://www.tngbbs.com
            ----------------------
            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

            Comment


            • #7
              Interesting but no cigar....
              Still returns a 1008 on GetLastError
              Code:
                                Control Get Text CbHndl,%ID_CHANGETEXT1 To ScriptDir
                                Control Get Text CbHndl,%ID_CHANGEPHYINSTALLTEXT To InstallDir 'Just in case it was manually typed
                                szName = ScriptDir
                                szPath = InstallDir
                                lResult = PathMakePretty(szPath)
                                'Delete Virtual Root on IIS (ScriptDir)
                                If OldszName <> ScriptDir Then lResult = DeleteVirtualRoot(OldszName, 1)
                                'Create Virtual Root on IIS (ScriptDir) /mp3
                                lResult = CreateVirtualRoot(szName,szPath,519,1,4)
              ------------------
              Scott
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #8
                Scott, have you printed out the ascii value of each character in
                ScriptDir and InstallDir?
                There has to be some funny character there - right?
                Can you make ScriptDir and InstallDir Asciiz strings?

                So, you have an INI file with something like:
                [FILEPATHS]
                ScriptDir=/mp3
                InstallDir=D:\TNGMP3

                Is this correct?

                Then you read this with GetPrivateProfileString() or some INI api?

                Ron

                Comment


                • #9
                  oops

                  [This message has been edited by Fred Oxenby (edited May 06, 2001).]
                  Fred
                  mailto:[email protected][email protected]</A>
                  http://www.oxenby.se

                  Comment


                  • #10
                    I'm going to convert every swinging string to an asciiz and test again....
                    It'll be 2nite before I can get it done though, daughter is here and keeping me busy


                    Thanks,

                    Scott

                    ------------------
                    Scott
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      Well I did it, everything ASCIIZ, same problem, weird...
                      The DeleteVirtual *ALWAYS* works........even weirder....


                      Code:
                      'These are for INI purposes only, not THIS application, for TNGMP3 ini.
                      Global InstallDir    As Asciiz * %MAX_PATH
                      Global TxFile        As Asciiz * %MAX_PATH
                      Global WOrkingDir    As Asciiz * %MAX_PATH
                      
                      Global FolderImage   As Asciiz * 128
                      Global VirtualDir    As Asciiz * 128
                      Global ScriptDir     As Asciiz * 128  
                      
                      
                      '
                      
                      '
                      Declare Function CreateVirtualRoot Lib "isssetup.dll" Alias "CreateVirtualRoot" (szName As Asciiz, szPath As Asciiz, ByVal Permissions As Dword, ByVal Site As Dword, ByVal Auth As Dword) As Integer
                      Declare Function DeleteVirtualRoot Lib "isssetup.dll" Alias "DeleteVirtualRoot" (szName As Asciiz, ByVal Site As Dword) As Integer
                      
                      'In Winmain:
                      
                      '
                      InstallDir = GetSetting(%HKEY_LOCAL_MACHINE, "SOFTWARE\Computer Creations Software\TNGMP3","InstallDir","")
                      g_IniFile = InstallDir & "\TNG.INI"
                      If IsFalse Exist(g_IniFile) Then
                         MsgBox g_IniFile & " does not appear to exist in it's location, save changes and the ini file will save to the INSTALL DIRECTORY",%MB_ICONWARNING,g_szCCS
                      End If
                      
                      
                      lResult = GetPrivateProfileString("Config","WorkingDir","",WorkingDir,SizeOf(WorkingDir),g_IniFile)
                      lResult = GetPrivateProfileString("Config","VirtualDir","",VirtualDir,SizeOf(VirtualDir),g_IniFile)
                      lResult = GetPrivateProfileString("Config","ScriptDir","",ScriptDir,SizeOf(ScriptDir),g_IniFile)
                      lResult = GetPrivateProfileString("Config","Template","",TxFile,SizeOf(TxFile),g_IniFile)
                      lResult = GetPrivateProfileString("Config","FolderImage","",FolderImage,SizeOf(FolderImage),g_IniFile)
                      lResult = GetPrivateProfileString("Config","BorderSize","",BorderSize,SizeOf(BorderSize),g_IniFile)
                      '
                      '
                      
                      'DialogProc
                          Case %WM_COMMAND
                            Select Case LoWrd(CbWparam)
                                   Case %IDCHANGE
                                        ChangeVirtualDirectory
                      
                      'ChangeVirtualDirectory:
                      
                      Function ChangeVirtualDirectory() As Long
                      
                      Dialog New hDlg, g_szMine,,,235,115,%WS_CAPTION To cDlg
                      Control Add Frame, cDlg,%ID_CHANGEFRAME,"Change virtual directories",1,1,232,85
                      
                      Control Add Label, cDlg,%ID_CHANGELABEL1,"Virtual Script Directory",5,15,80,10',%ES_RIGHT
                      Control Add TextBox, cDlg,%ID_CHANGETEXT1,ScriptDir,80,15,100,12
                      Control Add Label, cDlg, %ID_CHANGEPHYMP3LABEL1,"Physical Path",5,27,60,10',%ES_RIGHT,%WS_EX_CLIENTEDGE
                      Control Add TextBox, cDlg, %ID_CHANGEPHYINSTALLTEXT,InstallDir,80,27,100,12
                      Control Add Button, cDlg,%ID_CHANGEBROWSE1,"Browse",185,27,40,12 Call BrowseForPhysicalScriptPath
                      
                      Control Add Label, cDlg,%ID_CHANGELABEL2,"Virtual MP3 Directory",5,50,80,10',%ES_RIGHT
                      Control Add TextBox, cDlg,%ID_CHANGETEXT2,VirtualDir,80,50,100,12
                      Control Add Label, cDlg, %ID_CHANGEPHYMP3LABEL2,"Physical Path",5,62,60,10',%ES_RIGHT,%WS_EX_CLIENTEDGE
                      Control Add TextBox, cDlg,%ID_CHANGEPHYMP3TEXT,WorkingDir,80,62,100,12
                      Control Add Button, cDlg,%ID_CHANGEBROWSE2,"Browse",185,62,40,12 Call BrowseForPhysicalMP3Path
                      
                      Control Add Button, cDlg, %ID_CHANGEBUTTON,"Ch&ange",140,95,45,14,%BS_DEFAULT Or %WS_TABSTOP
                      Control Add Button, cDlg, %IDCANCEL,"&Cancel",185,95,45,14
                      'Attach icon
                      Dialog Send cDlg, %WM_SETICON, %ICON_BIG, g_hIcon
                      Dialog Show Modal cDlg Call ChangeProc To g_Result
                      End Function
                      '------------------------------------------------------------------------------------------
                      CallBack Function ChangeProc() As Long
                      Local lResult As Long
                      Static szName As Asciiz * 254
                      Static szPath As Asciiz * 254
                      Static OldszName As Asciiz * 254
                      Local szPrivilege As Asciiz * 7
                      
                      Select Case CbMsg
                          Case %WM_COMMAND
                            Select Case LoWrd(CbWparam)
                                   Case %ID_CHANGEBUTTON
                                        MousePtr 11
                                        SetPriorityClass GetCurrentProcess, %HIGH_PRIORITY_CLASS  'To speed things up a bit
                                        'Get privileges:
                      '                  szPrivilege = "System"
                      '                  lResult = GetPrivilege(szPrivilege)
                                        'Modify the virtual directory to the Script itself (TNGMP3)
                                        OldszName = ScriptDir
                                        Control Get Text CbHndl,%ID_CHANGETEXT1 To ScriptDir
                                        Control Get Text CbHndl,%ID_CHANGEPHYINSTALLTEXT To InstallDir 'Just in case it was manually typed
                                        'Delete Virtual Root on IIS (ScriptDir)
                                        If OldszName <> ScriptDir Then lResult = DeleteVirtualRoot(OldszName, 1)
                      
                                        'Create Virtual Root on IIS (ScriptDir) /mp3
                                        PathMakePretty InstallDir
                                        'Create Virtual Root on IIS
                                        lResult = CreateVirtualRoot(ScriptDir,InstallDir,519,1,4)
                      
                                        If IsFalse lResult Then
                                           lResult = GetLastError
                                           MsgBox "There was an error modifying the virtual directory: " & Format$(lResult),%MB_ICONSTOP,"Error"
                                        End If
                      
                                        'OK Now do the Virtual path to the MP3 files:
                                        OldszName = VirtualDir
                                        Control Get Text CbHndl,%ID_CHANGETEXT2 To VirtualDir
                                        Control Get Text CbHndl,%ID_CHANGEPHYMP3TEXT To WorkingDir 'Just in case it was manually typed
                                        lResult = PathMakePretty(WorkingDir)
                                        'Delete Virtual Root on IIS
                                        If OldszName <> VirtualDir Then lResult = DeleteVirtualRoot(OldszName, 1)
                                        'Create Virtual Root on IIS
                                        lResult = CreateVirtualRoot(VirtualDir,WorkingDir ,519,1,4)
                                        If IsFalse lResult Then
                                           '%ERROR_NO_TOKEN
                                           lResult = GetLastError
                                           MsgBox "There was an error modifying the virtual directory: " & Format$(lResult),%MB_ICONSTOP,"Error"
                                        End If   
                      
                                        Control Set Text hDlg, %ID_TNGVIRTUALDIRTEXT2,ScriptDir
                                        Control Set Text hDlg, %ID_TNGVIRTUALDIRTEXT4, VirtualDir
                                        SaveSettings 'Write ini file etc
                                        g_IsSaved = %TRUE
                                        SetPriorityClass GetCurrentProcess, %NORMAL_PRIORITY_CLASS  'To speed things up a bit
                                        Dialog End CbHndl,1
                      
                                   Case %IDCANCEL
                                        MousePtr 0
                                        Dialog End CbHndl,1
                            End Select
                      End Select
                      End Function
                      '------------------------------------------------------------------------------------------
                      ------------------
                      Scott

                      [This message has been edited by Scott Turchin (edited May 06, 2001).]
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        Can you post the C function prototypes/declares for the DLL?

                        Ron

                        Comment


                        • #13
                          This one? It's C++....
                          And the guy that wrote this is awesome, it does work good, this is definitely application specific...


                          Code:
                          /*
                          Function :  CreateVirtualRoot
                          
                          Description:
                          
                              Creates the specified virtual root
                          
                          Arguments:
                          
                              szName - Name of the virtual root to add
                              szPhysicalPath - Physical path of the virtual root
                              dwPermissions - Access permissions for the virtual root
                              dwSite - The site to which the virtual root is to be added
                              szStatus - The function can report error descriptions in this string
                          
                          Return Value:
                          
                              Returns TRUE if successfull; otherwise FALSE.
                          */
                          __declspec(dllexport) BOOL __cdecl  CreateVirtualRoot(
                              LPSTR szName,
                              LPSTR szPhysicalPath,
                              DWORD dwPermissions,
                              DWORD dwSite,
                          	DWORD dwAuth
                              )
                          {
                          ------------------
                          Scott
                          Scott Turchin
                          MCSE, MCP+I
                          http://www.tngbbs.com
                          ----------------------
                          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                          Comment


                          • #14
                            Scott, I will email you a PBCC file (source and .exe) and a DLL
                            I wrote in C comforming to the prototype you included in the previous message.

                            The .DLL will print a messagebox with the asciiz string data it received along with the 3 dword values.
                            There is a "!" placed at the end of each received Asciiz string.

                            Ron

                            PS: Scott, the email should be waiting:[email protected]??????r.???


                            [This message has been edited by Ron Pierce (edited May 06, 2001).]

                            Comment


                            • #15
                              Hi guys,
                              Preciate all the help, here's where it stands:

                              Code:
                              lResult = GetPrivateProfileString("Config","WorkingDir","",WorkingDir,SizeOf(WorkingDir),g_IniFile)
                              lResult = GetPrivateProfileString("Config","VirtualDir","",VirtualDir,SizeOf(VirtualDir),g_IniFile)
                              lResult = GetPrivateProfileString("Config","ScriptDir","",ScriptDir,SizeOf(ScriptDir),g_IniFile)
                              lResult = GetPrivateProfileString("Config","Template","",TxFile,SizeOf(TxFile),g_IniFile)
                              lResult = GetPrivateProfileString("Config","FolderImage","",FolderImage,SizeOf(FolderImage),g_IniFile)
                              lResult = GetPrivateProfileString("Config","BorderSize","",BorderSize,SizeOf(BorderSize),g_IniFile) 
                              
                              '
                              '
                              '
                              I can do a Msgbox on the value or length of the value and add a "!" to the end, life is good, it all works.
                              
                              '
                              '
                              Now, I do this, and it works and shows the correct values...
                              The DLL author has the error that his DLL trapped, so it may be there, but it may be my system too.....
                              DUnno, because his sample .BAs works fine, but it does the szPath="D:\TNGMP3" .
                              
                                                'Create Virtual Root on IIS
                                                MsgBox "Creating Virtual Directory: " & VirtualDir & "!" & " with a Physical Path of: " & WorkingDir & "!"
                                                lResult = CreateVirtualRoot(ScriptDir,InstallDir,519,1,4,szStatus)
                              
                              
                              Anyway, that works and returns a specific error.
                              Perhaps there is something in the pointer or something.
                              
                              I've also tried to send the DLL a StrPtr but that failed, usign VarPtr and Byval puts garbage in the Virtual root but DOES create it.....
                              ------------------
                              Scott
                              Scott Turchin
                              MCSE, MCP+I
                              http://www.tngbbs.com
                              ----------------------
                              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                              Comment


                              • #16
                                It's funny how the little things come back to bite you.

                                My drill sergeant used to say, "It's the little things that make a house a home, not the house".....


                                So, by removing the "/" from the virtual directory it works great........DOH!!!!!!!!!!!!!!!!

                                Thanks guys!


                                Scott

                                ------------------
                                Scott
                                Scott Turchin
                                MCSE, MCP+I
                                http://www.tngbbs.com
                                ----------------------
                                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                                Comment

                                Working...
                                X