I am currently setting up an Editor using Win32 as a challenge for myself but my Method for saving the file for some reason doesnt save the file. I checked multiple times with my resources and looked over threads on the internet but I either didnt have the problem that got solved there in the first place or it didnt help at all. Am I overseeing something here?
void SaveUserFile(HWND hwnd)
{
OPENFILENAME ofn;
char szFile[MAX_PATH] = "";
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
ofn.lpstrFile[0] = '\0';
ofn.hwndOwner = hwnd;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = TEXT("Text document(*.txt*)\0*.txt\0Word 2016 document(*.docx*)\0*.docx\0All Files(*.*)\0*.*\0");
ofn.nFilterIndex = 1;
ofn.lpstrInitialDir = NULL;
ofn.lpstrFileTitle = NULL;
ofn.lpstrDefExt = "mp";
ofn.Flags = OFN_PATHMUSTEXIST | OFN_HIDEREADONLY;
GetSaveFileName(&ofn);
}
GetSaveFileName does not save a file. It shows a dialog which allows the user to select a file name. If this returns successfully the program must then write the code to save the file, using the file name provided by the user which the program can read in szFile.
In new programs you should use the common item dialogs (IFileOpenDialog and IFileSaveDialog) rather than GetOpenFileName and GetSaveFileName. There are numerous reasons for this, but one of the most obvious is that you will not be limited in file name length.
I'm using C-API of Tensorflow 1.13.1.
After getting TF_Operation by TF_GraphOperationByName, I cannot find a method to get TF_Input or TF_Output, of which I want to get data type.
Below are the associated methods (https://github.com/tensorflow/tensorflow/blob/r1.13/tensorflow/c/c_api.h)
TF_CAPI_EXPORT extern int TF_OperationNumInputs(TF_Operation* oper);
TF_CAPI_EXPORT extern TF_DataType TF_OperationInputType(TF_Input oper_in);
In my opinion, it lacks a method like "TF_Input TF_OperationInput(int32_t index);"
TF_Operation *input_op = TF_GraphOperationByName(graph, "Placeholder");
int input_num = TF_OperationNumInputs(input_op);
for (int i = 0; i < input_num; ++i) {
// Expectation: auto oper_in = TF_OperationInput(i);
auto data_type = TF_OperationInputType(oper_in);
}
Please help me to find a way to get TF_Datatype from each TF_Input and TF_Output.
Thank you very much.
I think you are looking for TF_OperationInput() (link).
This methods receives a TF_Input (link) as an argument, which you can build using { input_op, i }.
I am writing an R package that contains C and Rcpp. The goal is to call the C function from R and within Rcpp, eventually performing most of the analysis in Rcpp and only returning to R for minimal tasks. My package compiles and calling my function from R works fine.
#generate some matrix. Numeric is fine too. Must have column names, no row names
myMat <- matrix(data = 1:100, nrow = 10, ncol = 10,
dimnames = list(NULL, LETTERS[1:10]))
#This works. Put in full path, no expansion. It returns null to the console.
MinimalExample::WriteMat(mat = myMat, file = "Full_Path_Please/IWork.csv",
sep = "," ,eol = "\n", dec = ".", buffMB = 8L)
However, attempting the same thing in Rcpp produces a SIGSEV error. I think the problem is how I am passing arguments to the function, but I can't figure out the proper way.
#include <Rcpp.h>
using namespace Rcpp;
extern "C"{
#include "fwrite.h"
}
//' #export
// [[Rcpp::export]]
void WriteMatCpp(String& fileName, NumericMatrix& testMat){
Rcpp::Rcout<<"I did start!"<<std::endl;
String patchName = fileName;
int whichRow = 1;
std::string newString = std::string(3 - toString(whichRow).length(), '0')
+ toString(whichRow);
patchName.replace_last(".csv", newString+".csv");
//Set objects to pass to print function
String comma = ",";
String eol = "\n";
String dot = ".";
int buffMem = 8;
//This is where I crash, giving a SIGSEV error
fwriteMain(testMat, (SEXP)&patchName, (SEXP)&comma, (SEXP)&eol,
(SEXP)&dot, (SEXP)&buffMem);
}
Here is a link to the GitHub repository with the package. https://github.com/GilChrist19/MinimalExample
Your call from C++ to C is wrong. You can't just write (SEXP)& in front of an arbitrary data structure and hope for it to become a SEXP.
Fix
Use a line such as this to convert what you have in C++ to the SEXP your C function expects using Rcpp::wrap() on each argument:
//This is where I crash, giving a SIGSEV error
fwriteMain(wrap(testMat), wrap(patchName), wrap(comma),
wrap(eol), wrap(dot), wrap(buffMem));
Demo
edd#brad:/tmp/MinimalExample/MinEx(master)$ Rscript RunMe.R
I did start!
edd#brad:/tmp/MinimalExample/MinEx(master)$ cat /tmp/IDoNotWork.csv
A,B,C,D,E,F,G,H,I,J
1,11,21,31,41,51,61,71,81,91
2,12,22,32,42,52,62,72,82,92
3,13,23,33,43,53,63,73,83,93
4,14,24,34,44,54,64,74,84,94
5,15,25,35,45,55,65,75,85,95
6,16,26,36,46,56,66,76,86,96
7,17,27,37,47,57,67,77,87,97
8,18,28,38,48,58,68,78,88,98
9,19,29,39,49,59,69,79,89,99
10,20,30,40,50,60,70,80,90,100
edd#brad:/tmp/MinimalExample/MinEx(master)$
See https://github.com/GilChrist19/MinimalExample/tree/master/MinEx for a complete example.
I have a function in C that takes a function callback as an argument in dll. It is OK for MFC and below is C code
void OnReceive(unsigned char* pReportBuf, int nReportLen, int nReportCount, SYSDELTA_TIME timeStamp) {
for (int iCount = 0; iCount < nReportCount; iCount++) {
BYTE *Buf = new BYTE[nReportLen + 1];
memcpy(Buf, &pReportBuf[iCount*nReportLen], sizeof(BYTE)*nReportLen);
SYSDELTA_TIME *sTime = new SYSDELTA_TIME;
memcpy(sTime, &timeStamp, sizeof(SYSDELTA_TIME));
}
}
res = InputRawRegHIDCallback(OnReceive);
Now I need to move above code to Python, but I don't know how to code
callback function to Python code. Could anyone help me to code???
Thank you for your great help.
BR,
Alan
Using ctypes, you can wrap/annotate the callback function with type information using CFUNCTYPE so they can be called from the C library.
I'm tasked with solving the following issue: My application crashes when running on a 64 bit machine when the PrintDlg() function is called.
After digging and hair pulling, I've decided the best solution is to replace the original calls of PrintDlg() with its bigger brother, PrintDlgEx().
Doing so fixes one problem (it no longer crashes!), but causes another. When I execute the code, it is not showing the print dialog, just returning a success code, and giving me all of the information for my default printer. I need this function to show the standard "print setup" window, I don't know how the heck to make it happen. Shown below are the sample values I'm trying to use to get my dialog to show.
Any thoughts? Thanks in advance.
// Initialize the PRINTDLGEX structure.
pd2.lStructSize = sizeof(PRINTDLGEX);
pd2.hwndOwner = wnddata->wnd.hnd;
pd2.hDevMode = NULL;
pd2.hDevNames = NULL;
pd2.hDC = NULL;
pd2.Flags = PD_RETURNDC | PD_COLLATE;
pd2.Flags2 = 0;
pd2.ExclusionFlags = 0;
pd2.nPageRanges = 0;
pd2.nMaxPageRanges = 10;
pd2.lpPageRanges = NULL;
pd2.nMinPage = 1;
pd2.nMaxPage = 1000;
pd2.nCopies = 1;
pd2.hInstance = 0;
pd2.lpPrintTemplateName = NULL;
pd2.lpCallback = NULL;
pd2.nPropertyPages = 0;
pd2.lphPropertyPages = NULL;
pd2.nStartPage = START_PAGE_GENERAL;
pd2.dwResultAction = 0;
pdrc = PrintDlgEx (&pd2);
You are most likely getting a return code of E_INVALIDARG, due to failure to read the fine print on the PRINTDLGEX structure. Specifically, it says "If the PD_NOPAGENUMS flag is not specified, lpPageRanges must be non-NULL."
The underlying problem with PrintDlg / PrintDlgEx is due to a missing attribute on your WinMain. You need to tag WinMain as [STAThreadAttribute] to indicate that your COM threading model is single-threaded apartment. Other threading models MAY work, but I can't say for sure.