|
Hi all, I am working on class to wrapp unmanaged pointer. I am just confused, whether pinning of value struct is needed in C++/CLI, i.e. whether if I will not do it, it can cause some problems.
In C#, I am not able to fix structs:
Point pntA = new Point(10, 25);
Point pntB = new Point();
unsafe
{
fixed (Point* ptrA = &pntA, ptrB = &pntB)
{
ptrB->X = ptrA->X;
ptrB->Y = ptrA->Y;
}
}
but, I can simply use address-of operator:
Point pntA = new Point(10, 25);
Point pntB = new Point();
unsafe
{
Point* ptrA = &pntA, ptrB = &pntB;
ptrB->X = ptrA->X;
ptrB->Y = ptrA->Y;
}
What is confusing me is that pin_ptr lets me pin structures as well as use address-of operator:
generic <typename T> where T : value struct
T GetValueA(void* ptr)
{
T val = Activator::CreateInstance<T>();
pin_ptr<T> valPtr = &val;
memcpy(valPtr, ptr, sizeof(T));
return val;
}
generic <typename T> where T : value struct
T GetValueB(void* ptr)
{
T val = Activator::CreateInstance<T>();
memcpy(&val, ptr, sizeof(T));
return val;
}
My questions are:
Is pinning needed in C++/CLI functions to fix value struct
before using its pointer in unmanaged function?
Are value structs allocated in the unmanaged heap?
Thanks all,
Dusan
modified on Wednesday, August 3, 2011 12:22 PM
|
|
|
|
|
I think you are asking at the wrong message board, try the Managed C++/CLI[^] one.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Aha, OK, thanks, I have overlooked that one...
|
|
|
|
|
It happens...
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Hi all,
Can you tell me how to get the msn status by programming, any program language is ok, such as c/c++/java or asp/asp.net/php etc.
What I want is: enter a msn address, such as 'test@hotmail.com', and then the program can return the current status of that account(just online or offline is ok).
Thanks in advance.
Joul
|
|
|
|
|
Try one of the HttpWebRequest[^] calls.
The best things in life are not things.
|
|
|
|
|
thanks, but i don't know where i can get the msn status? can you give me some hints?
joul
|
|
|
|
|
I'm not sure what you mean by "msn status", the best you can do is send a web request and if it fails you can check the web response to try and ascertain why. Take a look at some of the links I found for more information.
The best things in life are not things.
|
|
|
|
|
Take a look around this[^], maybe it has what you need.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> //TODO: Implement signature here<
|
|
|
|
|
Lighter Joul wrote: Can you tell me how to get the msn status by programming
1. Define what you mean by that - exactly. Presumably by doing some sort of online interaction.
2. Determine exactly what protocol is needed to achieve that.
3. Create code that implements that protocol.
Last step is the only one that has anything to do with code.
|
|
|
|
|
The leader says the size of header part of Tcp protocol can be changed to increase transfer speed. What ways do you use to increase transfer speed? Especially some different transfer tools is using at the same time.
|
|
|
|
|
Data compression before transfer can increase transfer speed. It helps to know the type of data being transferred to choose an appropriate compression method.
|
|
|
|
|
Hello,
If am correct a DLL can access member functions of an application (.EXE)if the implementation is done within the header file (.h) and not within the .cpp. Something like inline functions.
Doing so may oblige us to make the source code visible since the header must be supplied with the application.
So my question is how to do to avoid this and to make visible only the declaration of the functions.
Many thanks for your kind help.
|
|
|
|
|
one way to handle this is with what's known as the "PIMPL" pattern.
PIMPL[^]
there are many many ways to implement it.
one way is with an abstract base class.
share the abstract base class header, which defines the public interface, and includes a "create" function.
then your implementation inherits from that base class.
exported .h
class baseClass
{
virtual int doCalc() = 0;
};
extern baseClass * createDerived();
private .h
class derivedClass : public baseClass
{
virtual int doCalc();
};
.cpp
baseClass * createDerived()
{
return (baseClass *) new derivedClass();
}
int derivedClass::doCalc()
{
return 9;
}
or, with more of a C interface, using a 'handle' paradigm:
.h
typedef void * myClassHandle;
extern myClassHandle createObject();
extern int doCalc(myClassHandle hnd);
.cpp
myClassHandle createObject()
{
return (myClassHandle) new myClass();
}
int doCalc(myClassHandle hnd)
{
myClass * p = (myClass*)hnd;
return p->doCalc();
}
etc..
basically, you put a layer between your class and the caller.
|
|
|
|
|
In general you'll also export some kind of deleteObject function to avoid mixing heaps.
Steve
|
|
|
|
|
|
I've already given you a solution... if you only want to pass data back and forth, use data structures instead of passing pointers to classes.
|
|
|
|
|
Albert,
Thank you very much your help.
Actually I also want the DLL calls the application's functions.
So the idea was to pass a reference or a pointer of the class containing the functions.
and to call the functions with that object from within the DLL.
I do not know well how work structures. Do you mean that I can do so with a structure without being obliged to put the implementation of the functions in the header file?
|
|
|
|
|
I meant forget about calling functions from your DLL to your main application.
|
|
|
|
|
There is no point of having a DLL if it needs to call back into the application in this way. You would be better just adding the source functions into your application project.
The best things in life are not things.
|
|
|
|
|
Export function from exe and import in dll.
Below example is taken from http://www.codeguru.com/cpp/w-p/dll/article.php/c3649
In the EXE:
// Do exactly as you would export a DLL...
extern "C"
{
EXPORT void ExeFn(char * lpszMessage)
{
MessageBox(NULL,lpszMessage,"From Exe",MB_OK);
}
}
In the DLL:
...
// Get the handle of the EXE that loaded us.
FnPtrT FnPtr = (FnPtrT)::GetProcAddress(GetModuleHandle(NULL),
"ExeFn");
if(FnPtr)
(*FnPtr)("Message From The DLL");
else
MessageBox(NULL,"It Did Not work ,"From DLL",MB_OK);
...
|
|
|
|
|
I posted a question on here a few days ago and got a great deal of help. Hopefully someone will be able to help me again.
Some quick background: I've got very little experience with C++ and was thrown into a job that needed some custom application for a client's scanner. My background is in web development, so I may explain something incorrectly now and then.
Much of the code I'm working with is from the Canon CapturePerfect SDK.
The error I'm receiving is
error C3641:
The line causing this error reads:
int WINAPI CpCallBackFunc( int, WPARAM, LPARAM, DWORD );
The line is in a header file attached to the main document. Is there a way to adjust this so that the program will still run with clr:pure, or a clr support setting that will allow the function to compile without changing everything else? The project so far has been coded with clr:pure.
|
|
|
|
|
Thought the whole idea with clr:pure was to promise that you didn't performed calls into the native non-managed world.
I would probably move the logic calling the native CpCallBackFunc() into a seperate DLL compiled with just /clr. Then call this DLL from the clr:pure part.
You would then have to compile an x86 and an x64 of the DLL with the native calls
Alternative just change from clr:pure / clr:safe into standard clr.
|
|
|
|
|
I'm new to c++ so I'm not exactly sure how to go about attaching a DLL, or what exactly I'd put into the DLL.
I did adjust the CLR from pure to standard, it only produced more errors. I checked the sample of the API I have from Canon and noticed it had no clr.
When I change my project to have no clr, I received 4 errors.
"fatal error C1852: Printer_Application.pch"
Got the error 4 times on 4 separate files. Is there a solution to this?
|
|
|
|
|
if my OS use Classic theme, can I use XP theme only for my app, without affecting other windows?
|
|
|
|