简体   繁体   中英

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.

I have a version of a function, written by someone else, in Access VBA that I am trying to port to C#.

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. 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. 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.

Just remove &H from the string. VBA uses that to indicate "this is a hex value" but it isn't part of a valid hex string that C# can interpret.

Convert.ToUInt32("FFFFFFF0", 16)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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