I am writing some regression tests in WatiN and needed to make a couple POST web requests. The requests are working fine but I get an annoying dialog box asking me if I want to save the file or find a program online to open it. The line of code that is causing this is:
browser.Navigate2(ref uri, ref nflags, ref ntargetFrame,
ref dataBytes, ref headers);
Is anyone familiar with the Navigate2() method? Any idea on how to get rid of this download box?
Here is my answer:
The Navigate2() method looks like this:
HRESULT Navigate2(
VARIANT *URL,
VARIANT *Flags,
VARIANT *TargetFrameName,
VARIANT *PostData,
VARIANT *Headers
);
the flags can be defined as enum BrowserNavConstants like this:
typedef enum BrowserNavConstants {
navOpenInNewWindow = 0x1,
navNoHistory = 0x2,
navNoReadFromCache = 0x4,
navNoWriteToCache = 0x8,
navAllowAutosearch = 0x10,
navBrowserBar = 0x20,
navHyperlink = 0x40,
navEnforceRestricted = 0x80,
navNewWindowsManaged = 0x0100,
navUntrustedForDownload = 0x0200,
navTrustedForActiveX = 0x0400,
navOpenInNewTab = 0x0800,
navOpenInBackgroundTab = 0x1000,
navKeepWordWheelText = 0x2000,
navVirtualTab = 0x4000,
navBlockRedirectsXDomain = 0x8000,
navOpenNewForegroundTab = 0x10000
} BrowserNavConstants;
I used navUnstrustedForDownload and it did away with the download box. Hope this helps someone somewhere
Related
I am trying to underline the title for NSButton in Xamarin.MacOS.
In the mutable attributed string, I use
attrString.AddAttribute(NSStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
It doesn't work. Suggestions in Swift is to use
let underlineAttribute = [NSAttributedString.Key.underlineStyle: NSUnderlineStyle.single.rawValue]
In Xamarin.MacOS, there is no NSUnderlineStyle.Single.RawValue. How do I get the RawValue of NSUnderlineStyle enum? Thanks.
I am adding underline like this:
str.AddAttribute(NSStringAttributeKey.UnderlineStyle, new NSNumber((int)NSUnderlineStyle.Single), new NSRange(0, str.Length));
I can confirm this works in both NSTextView and NSButton
First, a quick review. NSUnderlineStyle is an enumeration with the following values:
NSUnderlineStyleNone = 0x00,
NSUnderlineStyleSingle = 0x01,
NSUnderlineStyleThick = 0x02,
NSUnderlineStyleDouble = 0x09,
NSUnderlinePatternSolid = 0x0000,
NSUnderlinePatternDot = 0x0100,
NSUnderlinePatternDash = 0x0200,
NSUnderlinePatternDashDot = 0x0300,
NSUnderlinePatternDashDotDot = 0x0400,
NSUnderlineByWord = 0x8000
So we could check the following code
string prefixedHex = "0x01";
int intValue = Convert.ToInt32(prefixedHex, 16);
NSMutableAttributedString str = new NSMutableAttributedString();
str.AddAttribute(NSStringAttributeKey.UnderlineStyle,NSNumber.FromInt32(1),range);
button.AttributedTitle = str;
There is nothing wrong with the original code.
attrString.AddAttribute(NSStringAttributeKey.UnderlineStyle, NSNumber.FromInt32((int)NSUnderlineStyle.Single), range);
I have forgotten to set this attribute in the OnElementPropertyChanged function.
Thanks for your confirmation that it works which prompts me to re-investigate my code. I spent a few days debugging it thinking that the issue is with rawValue.
Given a Bluetooth device address (represented by a SOCKADDR_BTH struct), is there a way to get the name of the device? using getnameinfo returns EAI_FAMILY ("The sa_family member of socket address structure pointed to by the sa parameter is not supported."):
// {B62C4E8D-62CC-404b-BBBF-BF3E3BBB1374}
DEFINE_GUID(g_guidServiceClass, 0xb62c4e8d, 0x62cc, 0x404b, 0xbb, 0xbf,
0xbf, 0x3e, 0x3b, 0xbb, 0x13, 0x74);
SOCKADDR_BTH SockAddrBthServer;
SockAddrBthServer.addressFamily = AF_BTH;
SockAddrBthServer.serviceClassId = g_guidServiceClass;
SockAddrBthServer.port = 0;
SockAddrBthServer.btAddr = //Filled with Bluetooth device address
char hostname[NI_MAXHOST] = {0};
char servInfo[NI_MAXSERV] = {0};
int ret = getnameinfo((struct sockaddr *) &SockAddrBthServer,
sizeof(SOCKADDR_BTH), hostname, NI_MAXHOST, servInfo, NI_MAXSERV, 0);
Use BluetoothGetDeviceInfo function to get remote device's name. Also you can resolve during discovering.
Please note that device name of NEW device may be empty if you try to read it right after discovering.
The best way is to subscribe for WM_DEVICECHANGE message (refer to MSDN WM_DEVICECHANGE and Bluetooth).
how to get the serial port name by my red pen. Not COM5.COM5 can be gotten by windows-API. If you know it, please let me know. I'll appreciate it!
enter image description here
Now, I can get both serial ports full name and COMX. But which is true? I know how to find true one by manual manipulation instead of my coding program. But how to find true one by my coding program.
enter code here
GUID classGuids = {0x4D36E978L, 0xE325, 0x11CE, 0xBF, 0xC1, 0x08, 0x00, 0x2B, 0xE1, 0x03, 0x18}; //GetClassGUIDs("ports"); //&GUID_DEVCLASS_PORTS
HDEVINFO hDevInfo = SetupDiGetClassDevs((LPGUID)&classGuids, NULL, NULL, 0);
if(hDevInfo)
{
SP_DEVINFO_DATA SpDevInfo={sizeof(SP_DEVINFO_DATA)};
for(DWORD iDevIndex=0; SetupDiEnumDeviceInfo(hDevInfo, iDevIndex, &SpDevInfo); iDevIndex++)
{
TCHAR szName[512] = {0};
if(SetupDiGetDeviceRegistryProperty(hDevInfo, &SpDevInfo, SPDRP_FRIENDLYNAME,
NULL, (PBYTE)szName, sizeof(szName), NULL))
{
_tprintf(_T("........%s\n"), szName);
}
}
SetupDiDestroyDeviceInfoList(hDevInfo);
Was hoping this might produce a compile time error but I guess I have just misunderstood how enums work...
enum SortDirection {
ascending = 1,
descending = -1
}
type IndexSpec = {[index: string]: SortDirection};
var i: IndexSpec = {thing: 3}; // no compile time error
All numeric values are considered value enum values.
This is allowed because there's no distinction between flag and non-flag enums:
enum MyFlags {
Cool = 0x1,
Awesome = 0x2,
Neat = 0x4
}
var i: MyFlags = 5; // Cool | Neat
i'm working on porting this C API in go https://github.com/shammash/vde3, the library has is own event loop that use libevent, i'm using CGO.
the library require a full vde_event_handler that is composed this way
{event_add = 0x7fffe4de0db0, event_del = 0xc2000123a8, timeout_add = 0xc200000090, timeout_del = 0xc200010400}
a struct with a series of pointers to functions
during execution this field are set to NULL and i can't understand why, i think it may be the go garbage collector that (for some reason) find the reference dandling and remove them, but this shouldn't be the case
this is the incriminated function https://github.com/kurojishi/govde3/blob/master/govde.go#L23
func createNewEventHandler() *C.vde_event_handler {
var libevent_eh C.vde_event_handler
C.event_base_new()
return &libevent_eh
}
and here is a gdb log
(gdb) p *libevenet_eh
No symbol "libevenet_eh" in current context.
(gdb) p *libevent_eh
$1 = {event_add = 0x7fffe0000900, event_del = 0x30302e3028, timeout_add = 0x65736c6166, timeout_del = 0x0}
(gdb) info locals
libevent_eh = 0xc200000098
err = {__methods = 0x0, __object = 0x0}
(gdb) n
Breakpoint 1, govde.createNewEventHandler ()
at /home/kurojishi/golang/src/github.com/kurojishi/govde3/govde.go:23
23 func createNewEventHandler() C.vde_event_handler {
(gdb) info locals
$ret11 = {event_add = 0x7fffe4de0db0, event_del = 0xc2000123a8, timeout_add = 0xc200000090, timeout_del = 0xc200010400}
(gdb) n
Breakpoint 2, govde.createNewEventHandler ()
at /home/kurojishi/golang/src/github.com/kurojishi/govde3/govde.go:24
24 var libevent_eh C.vde_event_handler
(gdb) info locals
libevent_eh = {event_add = 0x0, event_del = 0x3, timeout_add = 0x7fffe4de0f8f, timeout_del = 0x7fffe4de0f8f}
$ret11 = {event_add = 0x0, event_del = 0x0, timeout_add = 0x0, timeout_del = 0x0}
You are allocating a new event handler in Go in createNewEventHandler, passing it to the C code in VdeContext.Init, and then dropping the pointer. The effect is that sometime after VdeContext.Init returns, the Go garbage collector will collect the event handler structure, even though the C code still has a pointer to it. The code will be left holding a pointer to memory that will change unpredictably.
When you allocate memory in Go and pass a pointer to C, you must keep the pointer alive in Go for as long as the C code needs to reference it.