I'm unable to delete a folder in Windows with the following code:
SHFILEOPSTRUCT shfo = {
NULL,
FO_DELETE,
path,
NULL,
FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION,
FALSE,
NULL,
NULL };
SHFileOperation(&shfo);
I need to use SHFileOperation instead of RemoveDirectory because I need to delete non-empty folders.
However, the function fails even if the value in path points to an empty local folder with full control of Everyone user, is double-null terminated (as requested by documentation), has no system, hidden or read only attribute...
Unfortunately the function does not return an error code (returns zero if successful, or nonzero otherwise) and calling GetLastError returns ERROR_SUCCESS...
Where is the error?
Solved...
The path variable wasn't actually double-null terminated because I used wcscpy_s that fills the string buffer (that I had previously filled with zeros) with the 0xFD value after the null char...
Related
I am trying to add title rows on an existing excel file (xlsx) with ClosedXML library and following code:
public void HandlePrintTitleRows(IList<int> sheetIndex)
{
using (_workbook = new XLWorkbook(_filePath))
{
foreach (var i in sheetIndex)
{
IXLWorksheet workSheet = _workbook.Worksheet(i);
workSheet.PageSetup.SetRowsToRepeatAtTop(1, 5);
}
_workbook.SaveAs(_filePath);
}
}
File path is from SaveFileDialog dialog and it opens seemingly correct as XLWorkbook.
I am receiving this exception message from the _workbook.SaveAs method:
Attribute 'xfId' should have unique value. Its current value '10'
duplicates with others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[21]Attribute 'xfId'
should have unique value. Its current value '12' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[24] Attribute 'xfId'
should have unique value. Its current value '50' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[55 Attribute 'xfId'
should have unique value. Its current value '50' duplicates with
others. in /x:styleSheet[1]/x:cellStyles[1]/x:cellStyle[59]"
StackTrace:
at ClosedXML.Excel.XLWorkbook.Validate(SpreadsheetDocument
package) in
C:\Git\ClosedXML\ClosedXML\Excel\XLWorkbook_Save.cs:line 90
at ClosedXML.Excel.XLWorkbook.CreatePackage(String filePath,
SpreadsheetDocumentType spreadsheetDocumentType, B...
I am not sure how to proceed with this problem, all tips would be greatly appreciated ! The excel file has been previously created by Telerik.Windows.Documents.Spreadsheet.Model.Workbook class and opens normally with excel application.
Open your original file (unmodified by ClosedXML) with the OpenXML SDK Validator to see if it's a valid file. If the validation errors occur in the original file, fix them, or you can disable validation in ClosedXML by using the SaveAs(_filePath, false) overload at your own risk.
I have been using asterisk to connect to adhearsion for my system. System originate call to a sip number by using follow script.
Adhearsion::OutboundCall.originate number,
from: call_from,
controller: controller ,
controller_metadata: {id: #id, initiate_from:'outbound'}
and cdr of asterisk is used to maintain call status. The number that i haved called (destination call number) is not shown in cdr report.:
`id`, `calldate`, `clid`, `src`, `dst`, `dcontext`, `lastapp`, `lastdata`, `duration`, `billsec`, `disposition`, `channel`, `dstchannel`,`amaflags`, `accountcode`, `uniqueid`, `userfield`, `answer`, `end`
'2015-07-03 11:29:21', '9801243867', '9801243867', '1', 'adhearsion-redirect', 'Dial', 'SIP/ncell-out/playback', 5.12455, 5.89977, ' ANSWER', 'SIP/ncell-out-00000002', NULL, 'DOCUMENTATION', NULL, '1435902231.2', NULL, '0000-00-00 00:00:00', '2015-07-03 11:29:21'
'2015-07-03 11:29:26', '9801243867', '9801243867', '1', 'adhearsion-redirect', 'Dial', 'SIP/ncell-out/9771002', 0.000001, 0, 'NO ANSWER', 'SIP/ncell-out-00000003', NULL, 'DOCUMENTATION', NULL, '1435902236.3', NULL, '0000-00-00 00:00:00', '2015-07-03 11:29:26'
Adhearsion call 1#adhearsion-redirect , 1 destination number.
Executing [1#adhearsion-redirect:1] AGI("SIP/ncell-out-00000004", "agi:async")
how should i get destination number in cdr instead of 1 when originate call from adhearsion?
(if I had enough rep to comment, I'd ask you to post your controller code so I know how the call gets to 1#adhearsion-redirect).
Looks like you could use a helper-context to store some data in the CDR before continuing on to the adhearsion-redirect context. The part I'm missing is how to redirect your existing setup to the helper context.
Here's an example of a helper-context. Since I don't know your controller code, you essentially need to make it Dial(Local/1234567890#helper-context) instead of Dial(Local/1#adheasion-redirect). Here's the context:
[helper-context]
exten=_X.,1,Set(CDR(userfield)=${EXTEN})
exten=_X.,n,Goto(1,adhearsion-redirect)
Basically what this does is let any extension match inside helper-context, and sets the "userfield" in the CDR to the number. (You could change this to other CDR fields, but this was NULL in your log, so it was ripe for the picking.) Then it forward on to the adhearsion-redirect context. Using the Dial I showed above, this would set CDR's userfield to 1234567890, or whatever number you wanted to dial.
I have associated the following function to a tests in order to select a row in a java table when a the row text matches an expected value :
Public Function GetRowWithCellText(ByRef oJTable, sColName, sText)
bChkText=FALSE
iRowCount=oJTable.GetROProperty("rows")
For iCounter=0 to iRowCount-1
sGetCellText=oJTable.GetCellData(iCounter, sColName)
If instr(sText, sGetCellText)>0 Then
bChkText=TRUE
GetRowWithCellText=iCounter
End If
Next
ReportingFunction bChkText, "Row with desired text"
End Function
RegisterUserFunc "JavaTable", "GetRowWithCellText", "GetRowWithCellText", TRUE
The function is well registered and I got it in the list of available functions for a java table.
However when trying to apply the function into a JavaTable in my application :
JTable.GetRowWithCellText msg.users.list.table.header.user , LOGIN
I get the following error :
Object required: 'msg'
Line (122): "JTable.GetRowWithCellText msg.users.list.table.header.user , LOGIN".
Please note that UFT is not recoginising cols of my table so I had inserted its value manually
It appears from the 'Object required' error that the value for 'msg' is not defined. The first part of msg.users.list.table.header.user refers to an object named 'msg'. If that object does not exist or has not be initialized, you may get that error.
You can break your statement up to confirm where the error is located. Change this statement
JTable.GetRowWithCellText msg.users.list.table.header.user , LOGIN
To these statements
Dim user
Set user = msg.users.list.table.header.user
JTable.GetRowWithCellText user, LOGIN
When you re-execute, you should get an error on the second line if there was an issue with msg; otherwise you will get an error on the third line if it is truly an issue with your function.
I have used column index instead of column name and it worked , I guess there is an issue with special characters.
Thanks
Why is it that when I call RtlDosPathNameToNtPathName_U on the path \\?\C:, instead of getting back
\??\C:
I get back
\??\C:\\\?\C:
which is clearly incorrect?
Code snippet (in D):
struct CurDir { UnicodeString DosPath; HANDLE Handle; }
extern (Windows) static bool RtlDosPathNameToNtPathName_U(
in const(wchar)* DosPathName, out UnicodeString NtPathName,
out const(wchar)* NtFileNamePart, out CurDir DirectoryInfo);
wchar[] toNtPath(const(wchar)[] path)
{
UnicodeString ntPath;
CurDir curDir;
const(wchar)* fileNamePart;
enforce(RtlDosPathNameToNtPathName_U(path.ptr, ntPath,
fileNamePart, curDir));
try
{ return ntPath.Buffer[0 .. ntPath.Length / ntPath.Buffer[0].sizeof].dup; }
finally { RtlFreeHeap(RtlGetProcessHeap(), 0, ntPath.Buffer); }
}
writeln(toNtPath(r"\\?\C:")); //Returns the weird string
Update:
I figured out the problem -- see my answer.
RtlDosPathNameToNtPathName_U is giving you the correct output. The reason you see a weird-looking character in the middle is because UNICODE_STRINGs are not required to be null-terminated (which I'm sure you know already). The file name \??\C:\ is a completely valid native-format file name. I suspect what you really want is to prepend the device name instead of just referring to the GLOBAL?? directory like what RtlDosPathNameToNtPathName_U has done.
To do that, simply call NtQuerySymbolicLinkObject on \??\x:, where x is the drive letter that the path is using, and prepend the result. If it's a UNC path, prepend \Device\Mup. And so on for the other types of paths (if there are any).
I figured out the problem myself, with #wj32's help: I'd totally forgotten that the input to RtlDosPathNameToNtPathName_U needed to be null-terminated, and my code didn't handle that properly. Thanks for everyone's help!
I'm banging my head against the wall on this one. I was looking at some old database reporting code written in VB6 and came across this line (the code is moving data from a "source" database into a reporting database):
rsTarget!VehYear = Trim(Str(rsSource!VehYear))
When rsSource!VehYear is Null, the above line generates an "Invalid use of Null" run-time error. If I break on the above line and type the following in the Immediate pane:
?rsSource!VehYear
It outputs Null. Fine, that makes sense. Next, I try to reproduce the error:
?Str(rsSource!VehYear)
I get an "Invalid use of Null" error.
However, if I type the following into the Immediate window:
?Str(Null)
I don't get an error. It simply outputs Null.
If I repeat the same experiment with Trim() instead of Str(), everything works fine. ?Trim(rsSource!VehYear) returns Null, as does ?Trim(Null). No run-time errors.
So, my question is, how can Str(rsSource!VehYear) possibly throw an "Invalid use of Null" error when Str(Null) does not, when I know that rsSource!VehYear is equal to Null?
Update: If I type the following in the Immediate window, it works as expected (no error occurs):
?Str(rsSource!VehYear.Value)
This outputs Null. Now, I know that rsSource!VehYear is actually an ADODB.Field instance, but Value is its default property, so Str should be operating on the Value property (which is Null). Even the error message ("Invalid use of Null") suggests that Str is receiving a Null parameter, but how can it treat Null differently in one case and not the other?
My only guess is the internal implementation of Str() is somehow failing to get the default property, and the "Invalid use of Null" error is happening for a different reason (something other than the parameter is causing the "Invalid use of Null", perhaps when it is trying to retrieve the default property from the Field object).
Does anyone have a more detailed, technical explanation for what is actually happening here?
In short:
?Str(rsSource!VehYear)
throws an "Invalid use of Null" error when rsSource!VehYear is Null, but
?Str(rsSource!VehYear.Value)
returns Null.
However, both Trim(rsSource!VehYear) and Trim(rsSource!VehYear.Value) return Null.
If you need a value other than a string, try using IsNull instead:
rsTarget!VehYear = IIf(IsNull(rsSource!VehYear), 0, rsSource!VehYear)
' Note 0 is the default value
The Str function will specifically check if a Null value is passed in and deal with it accordingly. When you pass in an object it attempts to convert the result of a default method to a String. The result of the default method is not passed into the Str method, but Field object is, so a check for the initial Null will fail. The Str function will continue to check the parameter type for datatypes that it supports when it realizes that it has an object, it will attempt to retrieve the default value. It doesn't re-attempt to deal with the default value as it did with the passed in argument, so the attempt to return a Null as a String will fail. It seems MS didn't expect a default value to be Null or any other invalid value for Str. For instance Str doesn't support an empty string either.
This was my workaround in the vb6-days:
rsTarget!VehYear = Trim(Str(rsSource!VehYear & ""))
the & "" will make sure there is allways at least an empty string to work with.
From memory, null database fields are Nothing (or possibly vbNull), which do not have the same rules applied to them as Null. You should just be able to do a quick check:
If (rsSource!VehYear Is Nothing) Then
' Null
Else
' Not null
End If