English 中文(简体)
从部分扼杀中找到全球原子
原标题:Find a Global Atom from a partial string
  • 时间:2011-04-21 21:20:55
  •  标签:
  • winapi

I can create an Global Atom using GlobalAddAtom and I can find that atom again using GlobalFindAtom if I already know the string associated with the atom. But is there a way to find all atoms whose associated string matches a given partial string?

例如,请允许我说,我有一个原子,其扼杀是“Hello, World>。 我后来如何通过寻找公正的“Hello”来发现这种原子?

最佳回答
问题回答

确实可以做到这一点,但只能通过对所有人进行扫描。 在LINQPad 5中,这可以在我的机器上的0.025秒钟中进行,因此速度相当快。 这方面的一个例子是:

void Main()
{
  const string atomPrefix = "Hello";
  const int bufferSize = 1024;
  ushort smallestAtomIndex = 0XC000;
  var buffer = new StringBuilder(bufferSize);
  var results = new List<string>();
  for (ushort atomIndex = smallestAtomIndex; atomIndex < ushort.MaxValue; atomIndex++)
  {
    var resultLength = GlobalGetAtomName(atomIndex, buffer, bufferSize);
    if (buffer.ToString().StartsWith(atomPrefix))
    {
      results.Add($"{buffer} - {atomIndex}");
    }
    buffer.Clear();
  }

  results.Dump();
}

[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern uint GlobalGetAtomName(ushort atom, StringBuilder buffer, int size);




相关问题
How to read exact number of bytes from a stream (tcp) socket?

In winsock, both the sync recv and the async WSARecv complete as soon as there is data available in a stream socket, regardless of the size specified (which is only the upper limit). This means that ...

AcquireCredentialsHandle returns SEC_E_NO_CREDENTIALS

I created a self-signed certificate (created using OpenSSL) and installed it into the Certificate Store using the Certificates MMC snap-in (CertMgr.msc) on Windows Vista Ultimate. I have managed to ...

Calling Win32 EnumThreadWindows() in C#

I m trying to get a call to EnumThreadWindows working, but I always get a Wrong Parameter-Error, although my code is nearly the same as this example on pinvoke.net. I don t know why this doesn t work: ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Handling multiple windows WIN32 API

HI I m trying to create an application in the Win32 environment containing more than one window. How do i do that? all the Win32 Tutorials on web i found only showed how to manage one window. How do i ...

Creating a thread in DllMain?

It seems that when a thread is created from within DllMain upon DLL_PROCESS_ATTACH it won t begin until all dll s have been loaded. Since I need to make sure the thread runs before I continue, I get a ...