Loading ...
Sorry, an error occurred while loading the content.

Re: [bugreport] libcall() cannot access envrionment variable set by vim

Expand Messages
  • Yasuhiro MATSUMOTO
    On Windows, vim uses C runtime library(probably msvcrt.dll). And it store the environment varibles in memory of process. It is passed to external processes at
    Message 1 of 5 , Feb 19, 2013
    • 0 Attachment
      On Windows, vim uses C runtime library(probably msvcrt.dll). And it
      store the environment varibles in memory of process. It is passed to
      external processes at the time of starting it. So dll can't get them
      via getenv. To solve this problem, one of way is add code calling
      SetEnvironmentVariales/putenv both into vim. Another way is add code
      calling GetDOSEnvironment instead of getenv into your dll. I'm not
      sure the second way.

      On 2/19/13, Jian <skyshore@...> wrote:
      > Hi,
      >
      > I'm using gvim 7.3 on MS Windows 7. I set a envrionment variable in VIM by
      > command like:
      > :let $PORT=19999
      > Then in my DLL, I read the variable via the standard C lib function:
      > getenv("PORT");
      > When I call the DLL function via
      > :echo libcall('mytest.dll', 'test','')
      >
      > but it fails to retrieve the variable. I tested it on Linux, it works as
      > expected.
      >
      > BR,
      > Jian
      >
      > --
      > --
      > You received this message from the "vim_dev" maillist.
      > Do not top-post! Type your reply below the text you are replying to.
      > For more information, visit http://www.vim.org/maillist.php
      >
      > ---
      > You received this message because you are subscribed to the Google Groups
      > "vim_dev" group.
      > To unsubscribe from this group and stop receiving emails from it, send an
      > email to vim_dev+unsubscribe@....
      > For more options, visit https://groups.google.com/groups/opt_out.
      >
      >
      >


      --
      - Yasuhiro Matsumoto

      --
      --
      You received this message from the "vim_dev" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php

      ---
      You received this message because you are subscribed to the Google Groups "vim_dev" group.
      To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
      For more options, visit https://groups.google.com/groups/opt_out.
    • skyshore
      According to MSDN, GetDOSEnvironment is 16bit-windows API and does not exist on 32bit-windows. I tried GetEnvironmentVariable() in my DLL but it still does not
      Message 2 of 5 , Feb 19, 2013
      • 0 Attachment
        According to MSDN, GetDOSEnvironment is 16bit-windows API and does not exist on 32bit-windows. I tried GetEnvironmentVariable() in my DLL but it still does not work.

        Jian

        2013/2/19 Yasuhiro MATSUMOTO <mattn.jp@...>
        On Windows, vim uses C runtime library(probably msvcrt.dll). And it
        store the environment varibles in memory of process. It is passed to
        external processes at the time of starting it. So dll can't get them
        via getenv. To solve this problem, one of way is add code calling
        SetEnvironmentVariales/putenv both into vim. Another way is add code
        calling GetDOSEnvironment instead of getenv into your dll. I'm not
        sure the second way.

        On 2/19/13, Jian <skyshore@...> wrote:
        > Hi,
        >
        > I'm using gvim 7.3 on MS Windows 7. I set a envrionment variable in VIM by
        > command like:
        >     :let $PORT=19999
        > Then in my DLL, I read the variable via the standard C lib function:
        >     getenv("PORT");
        > When I call the DLL function via
        >     :echo libcall('mytest.dll', 'test','')
        >
        > but it fails to retrieve the variable. I tested it on Linux, it works as
        > expected.
        >
        > BR,
        > Jian
        >
        > --
        > --
        > You received this message from the "vim_dev" maillist.
        > Do not top-post! Type your reply below the text you are replying to.
        > For more information, visit http://www.vim.org/maillist.php
        >
        > ---
        > You received this message because you are subscribed to the Google Groups
        > "vim_dev" group.
        > To unsubscribe from this group and stop receiving emails from it, send an
        > email to vim_dev+unsubscribe@....
        > For more options, visit https://groups.google.com/groups/opt_out.
        >
        >
        >


        --
        - Yasuhiro Matsumoto

        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php

        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.



        --
        --
        You received this message from the "vim_dev" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
         
        ---
        You received this message because you are subscribed to the Google Groups "vim_dev" group.
        To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
        For more options, visit https://groups.google.com/groups/opt_out.
         
         
      • mattn
        ... I make sure this. created dll with: ... __declspec(dllexport) char* foo(const char* name) { return getenv(name); } ... gcc -shared -o foo.dll foo.c ... let
        Message 3 of 5 , Feb 20, 2013
        • 0 Attachment
          On Wednesday, February 20, 2013 12:06:05 AM UTC+9, Jian wrote:
          > According to MSDN, GetDOSEnvironment is 16bit-windows API and does not exist on 32bit-windows. I tried GetEnvironmentVariable() in my DLL but it still does not work.
          >

          I make sure this.

          created dll with:

          === foo.c
          --------------------------
          __declspec(dllexport)
          char* foo(const char* name) {
          return getenv(name);
          }
          --------------------------

          gcc -shared -o foo.dll foo.c

          === foo.vim
          --------------------------
          let s:libfile = substitute(expand('<sfile>'), '.vim$', (has('win32')||has('win64'))?'.dll':'.so', '')
          let $FOO=localtime()
          echo libcall(s:libfile, "foo", "FOO")
          --------------------------

          And :so % on foo.vim

          I get correct values. Probably, your dll is not depend on same msvcrt.dll which vim is used.

          --
          --
          You received this message from the "vim_dev" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php

          ---
          You received this message because you are subscribed to the Google Groups "vim_dev" group.
          To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
          For more options, visit https://groups.google.com/groups/opt_out.
        • skyshore
          I looked the DLL dependencies via MS depends.exe, and found my compiled DLL depends on msvcrt.dll, but my gvim.exe does not have msvcrt.dll in the direct
          Message 4 of 5 , Feb 24, 2013
          • 0 Attachment
            I looked the DLL dependencies via MS depends.exe, and found my compiled DLL depends on msvcrt.dll, but my gvim.exe does not have msvcrt.dll in the direct dependency list (although some system module like shell32.dll depends on it). 

            And I use procexp tool to view the module list of the running gvim, and only the system defualt msvcrt.dll in the list.

            my gvim 7.3 is installed by the package from vim.org. I tried your codes and still nothing showed, whatever I use gcc or cl.exe to compile.

            2013/2/20 mattn <mattn.jp@...>
            On Wednesday, February 20, 2013 12:06:05 AM UTC+9, Jian wrote:
            > According to MSDN, GetDOSEnvironment is 16bit-windows API and does not exist on 32bit-windows. I tried GetEnvironmentVariable() in my DLL but it still does not work.
            >

            I make sure this.

            created dll with:

            === foo.c
            --------------------------
            __declspec(dllexport)
            char* foo(const char* name) {
              return getenv(name);
            }
            --------------------------

            gcc -shared -o foo.dll foo.c

            === foo.vim
            --------------------------
            let s:libfile = substitute(expand('<sfile>'), '.vim$', (has('win32')||has('win64'))?'.dll':'.so', '')
            let $FOO=localtime()
            echo libcall(s:libfile, "foo", "FOO")
            --------------------------

            And :so % on foo.vim

            I get correct values. Probably, your dll is not depend on same msvcrt.dll which vim is used.

            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php

            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.



            --
            --
            You received this message from the "vim_dev" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
             
            ---
            You received this message because you are subscribed to the Google Groups "vim_dev" group.
            To unsubscribe from this group and stop receiving emails from it, send an email to vim_dev+unsubscribe@....
            For more options, visit https://groups.google.com/groups/opt_out.
             
             
          Your message has been successfully submitted and would be delivered to recipients shortly.