|
Have you tried using the MarshalAs attribute?
|
|
|
|
|
No I haven`t. Could you give me an example how I could cast this?
|
|
|
|
|
Oh ok. Im not using Platform Invocation to interop. Instead I have referenced the dll into my project. Any ideas?
|
|
|
|
|
|
EDIT: I have no idea which forum to post this in, I would put it in a MFC or windows programming forum, but none exists, nor does a standard C++ forum - very strange why you don’t have a c++ or general windows programming board. I see .NET, but this is not a .NET function, I also see VC++, but that’s a software application. I tried, so please don’t give me hell for posting here :P
I an error after calling this function "6" which implies an invalid handle. I call CreateFile prior to ReadDirectoryChangesW as instructed by the MSDN documentation to get the handle to a folder and it succeeds. The handle looks plenty valid, but when I pass it to ReadDirectoryChangesW things dont seem to work. My buffer does not get formatted. I'm not even sure what its supposed to look like, but it doest change, and my Bytes Returned DWORD is unchanged too. I have tried using the asynchronous and synchronous method with no luck.
Without posting code, is there anything obvious that I am missing? My buffer is just an array of char’s. I call createfile exactly how it is described in MSDN under the ReadDirectoryChangesW documentation.
Form what I understand, once my buffer is set up using ReadDirectoryChangesW, I can then type cast it as a FILE_NOTIFY_INFORMATION* and then pull the info out of that it using that struct. However, I’m not even getting that far. GetLastError returns a 6 after ReadDirectoryChangesW.
Please help, I have spent way too much time in the debugger a this stupid function call, it is driving me up the wall, and it should not be this difficult. grrr!
|
|
|
|
|
All,
I have a "standard" Win32 DLL with the C header. I'd like to create a Managed C++ assembly (DLL) which can be used by the other .NET languages such as C# and VB.NET. Must I write all the code manually to expose the data structures and methods? Is there a tool or utility which will allow me to do this quickly?
I appreciate your help.
Thanks,
RB
|
|
|
|
|
You might take a look around over at:
www.PInvoke.net
If the standard Win32 DLLs were Type Libraries you could simply use the Type Library Importer to convert them to .NET assemblies (TlbImp.exe, it lives in the Program Files\Microsoft Visual Studio .NET folder).
Most people just use the Win32 functions in their code by using the DllImport attribute before the function declaration. You must add the line "using namespace System::Runtime::InteropServices;" to your code, and the DLLImport attribute requires that you supply a String object, for instance, "User32.dll" as a parameter.
You could, of course, do this for the entire DLL, but, it would keep you busy for awhile.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeinteropservicesdllimportattributeclasstopic.asp[^]
I think the reasoning behind the Interop method has to do with Type safety by the managing CLR.
|
|
|
|
|
hi
i am developing the vb.net desktop application. actually zip file which contains the access db file is stored on the ftp server. so now i want to download the access zip file from the ftpserver and then unzip the file and store the records to the sql server.
does any one can help me.
for the entire process i need to write the prog.
i dont know how to start and do.
please give the code for the same.
so first give the code for downloading the zip file from the ftp server.
and then how to unzip file and store the records in to the sql server.
Thanks in advance.
Thiru
|
|
|
|
|
LOL - another VB programmer who can't read.
Dude, this is the managed C++ forum.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
I want to add a button on windows Save As dialogue tool bar. I need information (name, path) about current document (which send Save As dialogue). From any documents I want to save them automatically in a fixed folder(s).
Best regards,
mihai_chioariu
|
|
|
|
|
You're doing this in managed C++ ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi Folks!
IJW doesn't seem to work for me.
In a managed class (__gc) the use of
|char *buffer1 = new char(16);
or
|char *buffer2 = new char[16];
or even
|char *buffer3 = (char*) malloc(16);
raises a System.NullReferenceException.
For new to work I linked against libc.lib.
Any help would be very much appreciated!
Thanks,
Eric
p.s. I could avoid this altogether if I could communicate with an unmanaged application through a named pipe, but I could not find named pipes in the framework. Aren't there any?
|
|
|
|
|
Are you trying to convert a String object in .NET into its data equivalent for usage in an unmanged application?
If so, you should read the documentation on Interop marshalling and, in particular the default conversions of the various data types into either COM or just unmanaged C++. The String object maps to several character array types and sometimes you have to use the MarshalAs attribute to make the operation happen smoothly.
|
|
|
|
|
No. I want to use a static library. To use it, I need a dynamically allocated char buffer. new and malloc raise exceptions. Thats the problem.
IJW seems to fail already. Thats why I will be porting the library completly to .net.
Thanks,
Eric
|
|
|
|
|
Actually, my problem is: I have 2 COM libraries, implemented as set of Dispatch objects for automation and set of Custom objects for C++ usage. And I'd like to write my own DLL based on on of those sets. The main question is: what language should I use??? I tryed C# with Dispatch objects set and found it rather slow. So, maybe I can use C# and set of custom interfaces, or shall I switch to C++.NET???
Vad
|
|
|
|
|
|
Hi,
I've a problem with the syntax of function pointers in C++ on Linux (GNU g++, RedHat). I can do all combinations except the one in the small example below. To explain what I want to do:
I want to port an application from Windows to Linux. I own a class A which stores data of any structure. Class A does not know anything about the structure of a data-record so it offers some function pointers where another program or class can connect a method to sort, print .. etc records of data. This methods are then called by Class A when adding, printing, storing etc.. data, which works fine on Windows with Borlands C-Builder using the __closure keyword when defining the Function Pointer. My Application-Class (Lets name it Class B) uses Class A to store polygons and also provides the needed methods for comparing etc, but the compiler complains about lines like ClassA->DoCompare = &ClassB::MyCompare using g++ on Linux.
Here is an example stripped down to the problem, myclass1->init() stores a pointer to its printing-method myclass->print1 to the function pointer of myclass2 (myprint), then myclass1->execprint is called by main. myclass1->execprint then calls myclass2->doprint which - using the function pointer - calls myclass1->print1.
#include <stdio.h>
class myclass2
{
public:
void (myclass2::*myprint)(char*);
void doprint(char* text)
{
(this->*myprint)(text);
}
};
class myclass1
{
public:
myclass2 *c2;
void init(void)
{
c2 = new myclass2;
c2->myprint = &myclass1::print1;
}
void execprint(char* text)
{
c2->doprint(text);
}
void print1(char* text)
{
printf("PRINT: %s\n", text);
}
};
main()
{
myclass1 *c1;
c1 = new myclass1;
c1->init();
c1->execprint("EXEC");
delete(c1);
}
The error Message of the compiler is:
<br />
class2.cpp: In member function `void myclass1::init()': <br />
class2.cpp:23: cannot convert `void (myclass1::*)(char*)' to `void <br />
(myclass2::*)(char*)' in assignment <br />
Funny, but when everything happens in one class, it works and the compiler is happy; But this is not the solution for my problem because I cannot merge the two classes:
#include <stdio.h>
class myclass2
{
public:
void (myclass2::*myprint)(char*);
void doprint(char* text)
{
(this->*myprint)(text);
}
void init(void)
{
myprint = &myclass2::print1;
}
void execprint(char* text)
{
doprint(text);
}
void print1(char* text)
{
printf("PRINT: %s\n", text);
}
};
main()
{
myclass2 *c1;
c1 = new myclass2;
c1->init();
c1->execprint("EXEC");
delete(c1);
}
Does someone have an idea how to solve this - and if there is no solution, how would you solve the problem when a class needs to call a function which is not known at development-time? (qsort() is a good example, here you need to deliver a comparing function, but qsort is not included in a class so its no problem);
Thanks in advance
Armini
|
|
|
|
|
Hello. I would like to get only the Date of a DateTimePicker control.
I know I can use:
DateTimePicker DTP;
String* Date = DTP->Value.get_Date().ToString();
My problem is that the Time is set to '00:00:00' and I don't want it inside my string.
What is the best why to get only the date out of a DateTimePicker control?
Thanks.
|
|
|
|
|
dateTimePicker1.Value.ToShortTimeString();
|
|
|
|
|
I'm trying to use two functions to print to the screen a letter from the alphabet or my name using asterisk * characters. Does anyone know how to do it?
none
|
|
|
|
|
This is the Managed C++ forum.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Hi,
I am new to C++ programming. I am using the following code to check if a file exists, if not then create a new file and input something into the file.
the code runs well for the first time and creates the file as desired, however if the file created is manually deleted from the specified directory then the file is no longer created. I don't why ????????
Appreciate any help in this regard
ifstream dbfile("/var/puremail/tmp/pm_db_down.txt");
if (!dbfile.is_open()) {
cout << "The file does not exist. Creating a new file" << endl;
ofstream dbfile ("/var/puremail/tmp/pm_db_down.txt");
dbfile << puremail.m_getTime << endl;
dbfile.close();
exit(2);
}
else {
// read the file and calculate the time for which the db is down
}
when this code is run for the first time the file was created and also the time was written into the file, however after deleting the dbfile if I again run the code, the file is no more created.
Appreciate any help in this regard.
Thanks,
Mohit.
|
|
|
|
|
Wrong forum.
In Managed .NET C++, you would do things entirely differently.
But, your code example is not that complicated. You don't indicate how the file was created in the first place. It could be pre-existing, created by another application, or any one of a number of different methods.
|
|
|
|
|
how to import jpg format file in c++
any ides,if yes will be highly appreciated
|
|
|
|
|
It's even easier than in Visual C++ version 6.
I assume you want to display this image (on a Form).
First create a Graphics object, using the new operator.
Then call DrawImage->FromFile (this function has numerous overloaded forms an will accept a .jpg format image file).
Then, if the application compiles, your .jpg file must reside in ther same directory as the executable.
You can read all about these techniques either in your Microsoft Visual C++ .NET documentation. or, go over to the MSDN site and search.
|
|
|
|