CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Posts
    6

    Smile CreateFile Help KimTu please

    I'd like to get CreateFile handle when I open a volume "C:\\" but I always get -1

    I test this in C++ I get 0xffffffff

    Can someone shed a light on this for me please ?

    Thanks

    Kim Tu

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: CreateFile Help KimTu please

    That's because it's a directory and not a file...

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Oct 2004
    Location
    Rocket City
    Posts
    220

    Re: CreateFile Help KimTu please

    0xffffffff is the same value as -1 for Int32.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CreateFile Help KimTu please

    Negative numbers are represented in 2's complement. The rule is like this: Represent the absolute value in binary then invert all bits then add 1.

    -1 = 0000 0000 0000 0000 0000 0000 0000 0001
    then invert
    1111 1111 1111 1111 1111 1111 1111 1110
    then add 1
    1111 1111 1111 1111 1111 1111 1111 1111
    and that is 0xffffffff.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: CreateFile Help KimTu please

    good hint Cilu on 2's complement
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

  6. #6
    Join Date
    Aug 2008
    Posts
    78

    Re: CreateFile Help KimTu please

    Try this:

    namespace CSCreateFile
    {
    class Program
    {
    static void Main(string[] args)
    {
    string filePath, fileName;
    filePath = "D:\\testDirectory\\";
    fileName = filePath + "test.txt";

    Directory.CreateDirectory(filePath);
    File.Create(fileName);
    }
    }
    }

    -Ricky

  7. #7
    Join Date
    Sep 2008
    Posts
    15

    Re: CreateFile Help KimTu please

    It is @"\\.\C:" not @"C:\"
    Enjoy coding!

  8. #8
    Join Date
    Mar 2008
    Location
    IRAN
    Posts
    811

    Re: CreateFile Help KimTu please

    it is what???
    Please rate my post if it was helpful for you.
    Java, C#, C++, PHP, ASP.NET
    SQL Server, MySQL
    DirectX
    MATH
    Touraj Ebrahimi
    [toraj_e] [at] [yahoo] [dot] [com]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured