Click here to Skip to main content
15,887,383 members
Home / Discussions / C#
   

C#

 
GeneralRe: How can I download a picture in powershell and display it in C#? Pin
turbosupramk324-May-16 12:04
turbosupramk324-May-16 12:04 
QuestionIDisposable with COM Pin
hpjchobbes19-May-16 5:13
hpjchobbes19-May-16 5:13 
AnswerRe: IDisposable with COM Pin
Gerry Schmitz19-May-16 5:35
mveGerry Schmitz19-May-16 5:35 
AnswerRe: IDisposable with COM Pin
Dave Kreskowiak19-May-16 5:36
mveDave Kreskowiak19-May-16 5:36 
GeneralRe: IDisposable with COM Pin
OriginalGriff19-May-16 6:16
mveOriginalGriff19-May-16 6:16 
GeneralRe: IDisposable with COM Pin
hpjchobbes19-May-16 7:19
hpjchobbes19-May-16 7:19 
GeneralRe: IDisposable with COM Pin
Dave Kreskowiak19-May-16 7:23
mveDave Kreskowiak19-May-16 7:23 
QuestionEnumResourceLanguages return false for resource type identified by Name Pin
noelblanc18-May-16 10:14
noelblanc18-May-16 10:14 
Hello, i use code from p/invoke to enumerate resources in a programme ( a little like resourcehacker does that ).
When the resource has a type with a name, my code display an error. It's ok for an ID. I place here a piece of result:
Type : MUI
Name: 1
erreur: -532462766
Type : 3
Name: 1
Language: 1033.
why in my source EnumResourceLanguages return false for resource type identified by Name ?

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.ComponentModel;
namespace test2Enumressource
{
    class Program
    {
      private const uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002;

      [DllImport("kernel32.dll", SetLastError = true)]
      private static extern IntPtr LoadLibraryEx(
        string lpFileName,
        IntPtr hFile,
        uint dwFlags);

      [DllImport("kernel32.dll", SetLastError = true)]
      private static extern bool FreeLibrary(IntPtr hModule);

#region équivalent des macros
      private static bool IS_INTRESOURCE(IntPtr value)
      {
          if (((uint)value) > ushort.MaxValue)
              return false;
          return true;
      }
      private static uint GET_RESOURCE_ID(IntPtr value)
      {
          if (IS_INTRESOURCE(value) == true)
              return (uint)value;
          throw new System.NotSupportedException("value is not an ID!");
      }
      private static string GET_RESOURCE_NAME(IntPtr value)
      {
          if (IS_INTRESOURCE(value) == true)
              return value.ToString();
          return Marshal.PtrToStringUni((IntPtr)value);
      }
#endregion équivalent des macros

#region Enumération des langues des ressources
      [DllImport("kernel32.dll")]
      static extern bool EnumResourceLanguages(IntPtr hModule, IntPtr lpszType,
          IntPtr lpName, EnumResLangDelegate lpEnumFunc, IntPtr lParam);

      private delegate bool EnumResLangDelegate(
          IntPtr hModule,
          IntPtr lpszType,
          IntPtr lpszName,
          ushort wIDLanguage,
          IntPtr lParam);

      private static bool EnumResLangCallback(
          IntPtr hModule,
          IntPtr lpszType,
          IntPtr lpszName,
          ushort wIDLanguage,
          IntPtr lParam)
      {
          Console.WriteLine("\t\tLanguage: {0}", wIDLanguage);
          return true;
      }
#endregion Enumération des langues des ressources

#region Enumération des noms des ressources
      [DllImport("kernel32.dll",
        CharSet = CharSet.Unicode, SetLastError = true)]
      static extern bool EnumResourceNames(
        IntPtr hModule,
        IntPtr lpszType,
        EnumResNameDelegate lpEnumFunc,
        IntPtr lParam);

      private delegate bool EnumResNameDelegate(
        IntPtr hModule,
        IntPtr lpszType,
        IntPtr lpszName,
        IntPtr lParam);

      static bool EnumRes(
          IntPtr hModule,
          IntPtr lpszType,
          IntPtr lpszName,
          IntPtr lParam)
      {
         Console.WriteLine("\tName: {0}", GET_RESOURCE_NAME(lpszName));
         bool bret =  EnumResourceLanguages(hModule, lpszType,
            lpszName, new EnumResLangDelegate(EnumResLangCallback), lParam);

         if (bret == false)
         {
             throw new Win32Exception(Marshal.GetLastWin32Error());
         }

          return true;
      }
#endregion Enumération des noms des ressources

#region Enumération des types des ressources
      private delegate bool d_EnumResourceTypes(
        IntPtr hModule,
        IntPtr lpszType,
        long lParam);

      [DllImport("kernel32", CharSet = CharSet.Unicode, SetLastError = true)]
      private extern static long EnumResourceTypes(IntPtr hModule, d_EnumResourceTypes callback, long lParam);

      static bool EnumResourceTypesCallback(IntPtr hModule, IntPtr lpszType, long lParam)
      {
          if (IS_INTRESOURCE(lpszType))
          {
              Console.WriteLine("Type : {0}", GET_RESOURCE_ID(lpszType));
          }
          else
          {
              Console.WriteLine("Type : {0}", GET_RESOURCE_NAME(lpszType));
          }

        if (EnumResourceNames(hModule,lpszType,
        new EnumResNameDelegate(EnumRes), IntPtr.Zero) == false)
        {
            Console.WriteLine("erreur: {0}", Marshal.GetLastWin32Error());
        }
        return true;
      }
#endregion Enumération des types des ressources

      [STAThread]
      static void Main(string[] args)
      {
          string  file = @"C:\windows\system32\notepad.exe";
          if (args.Length == 1){
              file = args[0];
          }
          IntPtr hMod = LoadLibraryEx(file, IntPtr.Zero, LOAD_LIBRARY_AS_DATAFILE);

        long lParam = 0;
        EnumResourceTypes(hMod, new d_EnumResourceTypes(EnumResourceTypesCallback), lParam);

        FreeLibrary(hMod);
      }
    }
}

AnswerRe: EnumResourceLanguages return false for resource type identified by Name Pin
noelblanc18-May-16 22:15
noelblanc18-May-16 22:15 
QuestionDraw 2 lines in a picture box and automatically measure the angle between the line Pin
Shithun NK18-May-16 6:23
Shithun NK18-May-16 6:23 
AnswerRe: Draw 2 lines in a picture box and automatically measure the angle between the line Pin
Pete O'Hanlon18-May-16 6:47
mvePete O'Hanlon18-May-16 6:47 
AnswerRe: Draw 2 lines in a picture box and automatically measure the angle between the line Pin
Matt T Heffron18-May-16 6:54
professionalMatt T Heffron18-May-16 6:54 
AnswerRe: Draw 2 lines in a picture box and automatically measure the angle between the line Pin
OriginalGriff18-May-16 8:10
mveOriginalGriff18-May-16 8:10 
Questionread blob from database Pin
teddddddddddd18-May-16 3:27
teddddddddddd18-May-16 3:27 
AnswerRe: read blob from database Pin
koolprasad200318-May-16 20:44
professionalkoolprasad200318-May-16 20:44 
AnswerRe: read blob from database Pin
Eddy Vluggen18-May-16 23:11
professionalEddy Vluggen18-May-16 23:11 
AnswerRe: read blob from database Pin
Member 120300006-Jul-16 14:58
Member 120300006-Jul-16 14:58 
QuestionProblems Related to E commerce APIs Pin
anokeha_prani17-May-16 20:51
anokeha_prani17-May-16 20:51 
AnswerRe: Problems Related to E commerce APIs Pin
Dave Kreskowiak18-May-16 2:17
mveDave Kreskowiak18-May-16 2:17 
QuestionDynamically Insert A Property Into A LINQ Query Statement Pin
MadDashCoder17-May-16 9:56
MadDashCoder17-May-16 9:56 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Sascha Lefèvre17-May-16 10:32
professionalSascha Lefèvre17-May-16 10:32 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
MadDashCoder17-May-16 10:34
MadDashCoder17-May-16 10:34 
GeneralRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Sascha Lefèvre17-May-16 11:06
professionalSascha Lefèvre17-May-16 11:06 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Dave Kreskowiak17-May-16 11:17
mveDave Kreskowiak17-May-16 11:17 
AnswerRe: Dynamically Insert A Property Into A LINQ Query Statement Pin
Matt T Heffron17-May-16 12:22
professionalMatt T Heffron17-May-16 12:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.