Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

Duc Axenn

@Duc Axenn
About
Posts
11
Topics
3
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Display Port to HDMI
    D Duc Axenn

    Best way is to begin by test with another cable / then test with another screen or tv. You will have more information to search wich part has a problem.

    Hardware & Devices question graphics

  • C# and c++/cli problem on x86 OS
    D Duc Axenn

    Hi, i made a library in c++/cli and beside a c# program calling it. Everything works fine when i compile on any cpu or x64 on my pc (x64os/x64proc). But if i compile for x86, c# part works fine, but when i use the c++/cli part i get the error "could not load file or assembly .... incorrect format" . I use user32.lib in the c++/cli, is it possible the problem come from here ? ---- Edit I think it's ok, i activated copy reference to output project but i'm not sure it was that.

    Managed C++/CLI help csharp c++ question

  • Optimizing this code ?
    D Duc Axenn

    lol , i didn't know it, it's cool to learn something new. I took this username on google with reference to The big Lebowski's movie, i'm pretty sure it's a wrong translation. Perhaps it's dude in english but in french he wants to be called The Duc, what is a total paradox with all of he is. It's true that it could interpreted as something pretentious, i'm happy you understood it was not at all for this reason. It's interesting to discover a particularity of another language. Thanks for all, sinceraly. - Alexandre CODOUL.

    C / C++ / MFC performance help csharp c++ com

  • Optimizing this code ?
    D Duc Axenn

    Thanks i will read all of that, it's not as simply as c# ^^.(i must remember DWORD is unsigned, it's more simple with c#, with int or uint,...). I just saw it's a byte value furthermore. It's true for the function. I think to myself it was implicitly said, but it's true that for the one that never seen it before i should think to put the function. I was working about how use handle and reference, it's more easy in c# about that.

    C / C++ / MFC performance help csharp c++ com

  • Optimizing this code ?
    D Duc Axenn

    Seriously... i hate myself, I was so sure that it will be something weird that i 've make a quick refresh of my knowledges on c++, as i said there was years i touch it. I took some notes for the future this time, i'm pretty sure i have already dit it but i don't remember where are this notes... Thanks to that damn sickness. I can't verify for a spanned volume, if somebody can it will great, last time i tried JODB it was on a netgear NAS that doesn't want anything else except it or raid 1 for the two bay it has. I tried JODB then one of the drives failed i understood how life could be fun... For the code... if you could give me your feedback, because i recognize it's a bit special to understand how DeviceIOControl works with IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, but finally.. basically by running in debug mode i explored content of extents and realized there were an array... *ù*ù$^% of me. What could say QBert ? "@!#@?!" or something like these. I was so sure to found something weird, another handle with a special iteration behind... No. Then i modified the part at the end, i let the if conditionnal to avoid problems in case of i retrieve nothing. I don't know if c++ allow to use something like extents?.Extents.Any(). Is there something near that in c++ ?

    if (extents)
    {
    vector interfaces;
    for (DWORD i = 0; i < extents->NumberOfDiskExtents; i++)
    {
    // process the extents
    int physicalDriveNumber = extents->Extents->DiskNumber;

    		/\*
    			Once you have the physical drive numbers, you can convert them to physical drive  
                handles by building a path of the form
    			\\\\.\\PhysicalDrive# where the # is the decimal expansion of the drive number.
    		\*/
    
    		wchar\_t physicalDrivePath\[80\];
    		swprintf\_s(physicalDrivePath, L"\\\\\\\\.\\\\PhysicalDrive%d", physicalDriveNumber);
    		driveHandle = CreateFile(physicalDrivePath,
    			0, FILE\_SHARE\_READ | FILE\_SHARE\_WRITE | FILE\_SHARE\_DELETE,
    			nullptr, OPEN\_EXISTING, 0, nullptr);
    
    		interfaces.push\_back( GetInterfaceType(driveHandle));
    	}
    
    	return interfaces;
    }
    

    In the example i stay with int values that could be used as i want, i'm pretty sure i will stay on c#, i want to enhance an existing explorer system i made for my other applications and i don't know for the while how to call a windows written with something else than winform. I don't even know if it's possible. Do you think it's ok now ? I'm very dumb to didn't see it at the beginning. Edit --- (Thanks to Randor)

    C / C++ / MFC performance help csharp c++ com

  • Optimizing this code ?
    D Duc Axenn

    thanks for your answer i was pretty sure to have an answer like that, i asked myself for the special cases. As i said most of the code is not mine, it began by an example about path, i will modify function to ask the path but it is the purpose. I was reading a code here in vba yesterday, that uses also the CreateFile instruction when suddenly i remembered about extents ... But i didn't know it was possible to mix with different ports because of the controler. But i forget about virtual raid and some other things... I think about the same problem will come in the other case (i didn't finish this part) if i begin by list all physical drive => volume => drive letter. In my case if i take in charge your advice, enumerate all as you said behind with this information the function calling will have to manage according of its own purpose. Staying neutral by just transmit ports used... And you are right, i was so happy to get the port that i totally forgot about the case you discribed. Big thanks :thumbsup:, but i hate you as much i like you :laugh: ... i must work more in c++ now :-D . If you see anything else i made wrong i will happy to get more advices. Best regards.

    C / C++ / MFC performance help csharp c++ com

  • Optimizing this code ?
    D Duc Axenn

    Hi, i'm a beginner in c++, i have already did some little projects but there is many years and i don't remember the most of things. I'm on c#, since many years (+a sickness that ruins my life, not good for the memory). After several days of research, testing wmi, registry, c# c++/cli etc to measure performance, there was something i would find, how to remote since a drive letter (or path here) to know interface type. I finally found another articles of Raymond Chen, 90% of this code was already written by him i just made the link between and add what was missing. I understood the most of this, but i forgot a lot of syntaxes, memory management and few other things, because most of them are managed by c#. Then i would submit this code to know if there wase some things i could optimize, and most important if i correctly did things to not have an hardware problem beside. Raymond Chen's blog Futhermore i hope it will help others.

    LPCWSTR filePath = L"H:";
    HANDLE volumeHandle = NULL;
    HANDLE driveHandle = NULL;
    
    
    // Récupère le nom du volume
    // Get volume name
    TCHAR volumePath\[MAX\_PATH\]; // for expository purposes
    bool res = GetVolumePathName(filePath, volumePath, ARRAYSIZE(volumePath));
    wprintf(L"%s \\n", volumePath);
    
    /\*
    	Récupère le GUID (ne marche pas si c'est pas un disque dur local) \\\\?\\Volume{guid}\\
        Get Guid (doesn't work if it's not a local disk) \\\\?\\Volume{guid}
    \*/
    TCHAR volumeName\[MAX\_PATH\]; // for expository purposes
    GetVolumeNameForVolumeMountPoint(volumePath, volumeName, ARRAYSIZE(volumeName));
    
    wprintf(L"%s \\n", volumeName);
    
    /\* Raymond Chen's notes:
    	If you pass that path to the CreateFile function with the trailing backslash intact, then you 
        are opening a handle to the root directory of the volume.
    	If you pass that path to the CreateFile function with the trailing backslash removed, then you 
        are opening a handle to the volume itself.
    \*/
    
    // In our case, we want to open a handle to the volume itself, so we need to remove that trailing    backslash.The call to CreateFile looks like this:
    CString test = volumeName;
    test.TrimRight('\\\\');
    
    LPCWSTR volumeNameWithoutTrailingBackslash = test;
    
    // Handle sur le volume (en retirant le dernier \\)
    // Handle on volum (by removing last \\)
    volumeHandle = CreateFile(volumeNameWithoutTrailingBackslash,
    	0, /\* no special access requested \*/
    	FILE\_SHARE\_READ | FILE\_SHAR
    
    C / C++ / MFC performance help csharp c++ com

  • Optimizing this code ?
    D Duc Axenn

    Hi, it's not an alternative i just filled the element missing to perform what i need, 90% of the code came from Raymond Chen's blog. I've seen many people would know as me, how to find if a logical drive was usb, etc... I'm not enough good to c++ to make an article with it. I just want to verify with the community if there is no problem with the way i close handle, if there is things i didn't see. Et cetera. c++ code i made by the past was not about windows api, was just simple ui then i gone to java then c# (worst is i have a sickess doing i lost a big part of what i learnt). About the code, I saw many people using WMI but WMI could reach until 8s as i measured yesterday to retrieve information (i've hard 7 hard drive, 4 in usb 3) what is for a local application is a non-sense. Some others think DriveType is an hard disk is usb, what is false. An hard disk is considerate as "fixed" (Worse is for c# developper as me, there is no all possibilities we have with c++ except by c++/cli and it's not really a good idea to check logical drive by logical drive with c++/cli, it's slow in compareason. We need DriveInfo in c# it's slow. This is why step by step i search with c++/windows api how to do and have something quick and each time i find an algorithm doing the job (by combining, searching etc...) i post for others. Things evoluted since 2003, and i found hard to sort what it's deprecated, most of answers i found, people use workarounds. And c# get logical drives give me not at all what i need, i'm frustrated :cool:. Sorry for this long post. :java:

    C / C++ / MFC performance help csharp c++ com

  • Get folders like the one for mega, drop box
    D Duc Axenn

    Hi, i have an hexadecimal value for the return value. I ask myself if i must continue to this way, i read somewhere else it was an old way to do it like a c++ copy/paste. I would to have something quick, with all default icons (i don't know another way for folders than to use win32.dll this is why i thought about make all with api methods) Meanwhile, to go forward i found a way to get mega folders, i post here if it can help others.

            var identity = System.Security.Principal.WindowsIdentity.GetCurrent();
            string userName = identity.Name.ToString();
            string userSID = identity.User.ToString();
            List MegaFolderPaths = new List();
    
            RegistryKey clsidKey = Registry.Users.OpenSubKey($"{userSID}\\\\Software\\\\Classes\\\\CLSID");
    
            //Get all the sub keys it contains
            foreach (string subKey in clsidKey.GetSubKeyNames())
            {
                RegistryKey clsidSubKey = Registry.Users.OpenSubKey($"{userSID}\\\\Software\\\\Classes\\\\CLSID\\\\{subKey}\\\\Instance\\\\InitPropertyBag");
    
                if (clsidSubKey == null)
                    continue;
    
                string defaultValue = (string)clsidSubKey.GetValue("TargetFolderPath");
    
                if (!string.IsNullOrEmpty(defaultValue))
                    MegaFolderPaths.Add(defaultValue);
            }
    

    ------------------- Edit: for the chinese character i didn't see i forgot to add this

    [DllImport("shell32.dll", CharSet = CharSet.Auto)]

    above

        public static extern Int32 SHGetFileInfo(IntPtr pIDL, uint dwFileAttributes,
                                out SHFILEINFO psfi, uint cbFileInfo, uint uFlags);
    
    C# csharp asp-net dotnet windows-admin question

  • Get folders like the one for mega, drop box
    D Duc Axenn

    hi, thanks for your answer. I tried several things, even before i tried to read sources from this example I used

    IntPtr m_pIDL = IntPtr.Zero;
    hRes = ShellAPI.SHGetSpecialFolderLocation(IntPtr.Zero, CSIDL.CSIDL_DESKTOP, ref m_pIDL);

    but it's deprecated, so i used

            hRes = ShellAPI.SHGetFolderLocation(IntPtr.Zero, 0, IntPtr.Zero,0, out m\_pIDL);
    

    For retrieve informations i used

            SHFILEINFO shInfo = new SHFILEINFO();
            ShellAPI.SHGetFileInfo(m\_pIDL, 0, out shInfo, (uint)Marshal.SizeOf(shInfo),
                SHGFI.DisplayName | //0x000000200
                SHGFI.PIDL | //0x000000008
                SHGFI.SmallIcon |//0x000000001
                SHGFI.SystemIconIndex //0x000004000
            );
    

    But i get

    畂敲畡

    as display name, and 34 as iIcon in all cases. Which means "toc toc" (knocking) according to google translate. I can't go more forward, i'm totally blind because of that. This example is interesting because it give me what i need, i have one drive & mega folders and it seems there is no special instruction to have it, it lists elements by using

    EnumObjects

    This is why i would to use some elements under .net core and learn how to use windows api, instead of using c# with methods from Directory. If i understand well it's a handle (pointeur?). SHFILEINFO

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct SHFILEINFO
    {
    public IntPtr hIcon;

        public int iIcon;
    
        public uint dwAttributes;
    
        \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)\]
        public string szDisplayName;
    
        \[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)\]
        public string szTypeName;
    }
    
        \[DllImport("shell32.dll")\]
        //public static extern Int32 SHGetFolderLocation(IntPtr hwnd, int csidl, HANDLE hToken, DWORD dwFlags, PIDLIST\_ABSOLUTE\* ppidl);
        public static extern int SHGetFolderLocation(IntPtr hwndOwner, int csidl, IntPtr hToken, uint dwReserved, out IntPtr ppidl);
    
    
        \[DllImport("shell32.dll", CharSet = CharSet.Auto)\]
        public static extern IntPtr SHGetFileInfo(string path, uint attributes, out SHFILEINFO fileInfo, uint size, uint flags);
    
        \[DllImport("shell32.dll")\]
        public static extern IntPtr SHG
    
    C# csharp asp-net dotnet windows-admin question

  • Get folders like the one for mega, drop box
    D Duc Axenn

    Hi, i would to make an explorer to add some methods i need behind. I tried a lot of things but many are deprecated. I'm under windows 10 x64. I want to make my app under .net core. I tried SHGetSpecialFolderLocation but the name i retrieve is in chinese... i don't understand why. I saw with windows 10 it's better to use knownfolderid but i search in my registrykeys and i didn't find mega key, but it uses a clsid. Should it a good idea to ask to the registry or is there another method ? i want to make something classic, with "mycomputer" root, make drives under it (it's ok for this part), have clouds folder also... And i will try to get default icons, i have some methods using win32.dll (if you have better i will happy to have more informations).

    C# csharp asp-net dotnet windows-admin question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups