简体   繁体   English

如何将 VBA long &HFFFFFFF0 转换为 uint 以在 C# 中使用?

[英]How do I convert the VBA long &HFFFFFFF0 to a uint for use in C#?

I've seen few examples that work for me.我见过几个对我有用的例子。 So I wanted to ask a new question.所以我想问一个新问题。 I am specifically trying to use the AccessibleObjectFromWindow method from oleacc.dll.我特别想使用 oleacc.dll 中的 AccessibleObjectFromWindow 方法。

I have a version of a function, written by someone else, in Access VBA that I am trying to port to C#.我有一个由其他人编写的函数版本,在我试图移植到 C# 的 Access VBA 中。

the code in question is:有问题的代码是:

    public static bool GetReferenceToApplication(long hWndXL, out object oApplication)
{
    oApplication = null;
    long hWinDesk = (long)FindWindowEx(new IntPtr(hWndXL), new IntPtr(0), "XLDESK", string.Empty);
    long hWin7 = (long)FindWindowEx(new IntPtr(hWinDesk), new IntPtr(0), "EXCEL7", string.Empty);
    Guid guid = new Guid("00020400-0000-0000-C000-000000000046");
    object obj = null;

    if (AccessibleObjectFromWindow(new IntPtr(hWin7), Convert.ToUInt32("&HFFFFFFF0", 16), ref guid, ref obj) == RETURN_OK)
    {
        oApplication = obj;
        return true;
    }
    else return false;
}

Convert.ToUInt32("&HFFFFFFF0", 16) does not work. Convert.ToUInt32("&HFFFFFFF0", 16) 不起作用。 I know I am doing something wrong here, I do not know what exactly that is.我知道我在这里做错了什么,我不知道那到底是什么。 In VBA, I think the ampersand denotes a long.在 VBA 中,我认为&符号表示很长。 But, I'm not too familiar with this sort of thing yet.但是,我对这种事情还不太熟悉。 Any help would be appreciated.任何帮助,将不胜感激。 I get an exception now matter which way I try to convert this value to a uint.我现在遇到一个异常,无论我尝试以哪种方式将此值转换为 uint。

Just remove &H from the string.只需从字符串中删除&H VBA uses that to indicate "this is a hex value" but it isn't part of a valid hex string that C# can interpret. VBA 使用它来指示“这是一个十六进制值”,但它不是 C# 可以解释的有效十六进制字符串的一部分。

Convert.ToUInt32("FFFFFFF0", 16)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM