|
Thanks for the response. I will look into it.
Bob
|
|
|
|
|
|
I have a problem using a C++ written Dll using strings to return values.
Could someone give me a hint how to write a dll function to be used in C++ and C#.
At the moment I only found solutions working for C# or C++ but not both. Other language always have memory trash after calling the function, because the "original" variable within the dll is destroyed after call.
I would like to get hints which type to use for implementation within the dll.
I could change all progs, C++, C# and dll. So any solution would be helful to me.
Simple example how it would be simplest, but of course not working:
C++ Prog :
CString ReturnBuffer;
CallDllFunction(ReturnBuffer)
C# Prog :
string ReturnBuffer;
CallDllFunction(ReturnBuffer);
Dll (C++)
void CallDllFunction(CString &ReturnBuffer)
{
CString Test = "Teststring";
ReturnBuffer = Test;
}
Hope someone could help me. Thanks.
|
|
|
|
|
C# doesn't know anything about CString so it can't marshal as a String.
You could maybe use a LPWSTR as a parameter...here's a string-safe example:
extern "C" __declspec(dllexport) void CallDllFunction(LPWSTR ReturnBuffer, int buflen)
{
CStringW Test = L"Teststring";
wcscpy_s(ReturnBuffer, buflen, Test);
}
[DllImport("TestWin32DLL.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern void CallDllFunction(StringBuilder buf, int buflen);
static void Main(string[] args)
{
StringBuilder sb = new StringBuilder(260);
CallDllFunction(sb, 260);
...
extern "C" __declspec(dllimport) void CallDllFunction(LPWSTR ReturnBuffer, int buflen);
void somefunc()
{
CStringW ReturnBuffer;
CallDllFunction(ReturnBuffer.GetBuffer(260), 260);
ReturnBuffer.ReleaseBuffer();
...
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Much thanks. This worked for me, but it was a hard fight to make it run within the programs I needed it. But finally it did. It helped me a lot.
I knew that CString (C++) and string (C#) is not the same. Example only was to demonstrate what I wanted.
|
|
|
|
|
You're making a wrong assumption when you pass C# string class as C++ CString class. The fact that string sounds like CString doesn't make the two classes equivalent. CString is a C++ class, and C# doesn't have it.
Better make a function that takes a pointer and size as parameters, then fills them with the string.
void CallDllFunction(const char* buffer, int n)
{
CString Test = "Teststring";
strncpy(buffer, Test, n);
}
There is sufficient light for those who desire to see, and there is sufficient darkness for those of a contrary disposition.
Blaise Pascal
|
|
|
|
|
hi
i have a dialog based MFC application with a web browser control
i have created it dynamicaly with CWnd wrapper class
i am creating control like below
and i want to control contex menu of the web browser
int CHolderWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
DWORD dwStyle = WS_CHILD|WS_VISIBLE;
m_pWebCtrl = new CWebBrowser2;
if(!m_pWebCtrl->Create(NULL,NULL,dwStyle,CRect(0,0,0,0),this,ID_WEB_WINDOW))
{
return -1;
}
return 0;
}
after some search i found this link http://msdn.microsoft.com/en-us/library/aa770042(VS.85).aspx[^]
but i do not know how to use it
can you give me a clue about how to start this task
thank you
|
|
|
|
|
|
Hello,
I wrote a COM object (for WinMobile 6) that handles the download of specific mime types and extensions, using IPersistMoniker and IBindStatusCallback interfaces implementations.
I've registered the CLSID and the mime types and extensions I need.
Download of direct links works great, the problem starts when trying to download a link with content disposition attachment in its header - my DLL is being loaded, and IUnknown and IPersistMoniker interfaces are being requested as they should - but release right after the QueryInterface.
I've noticed that those links (with the content disposition) ignore the mime type registration and follow only the extension regstration (with CLSID or ProgID). Also, if I edit the extension key to run some EXE file (even iexplore) instead of my DLL - it works well.
How should I handle links with content disposition?
Thanks,
Keren
|
|
|
|
|
|
Hi,
how do I use GetProcessID? I couldn't find any articles at MSDN!
Ive already searched and put this into my code:
GetProcessID("cmd.exe");
but my compiler (g++) says that it was not declared!?
I included windows.h and iostream, do I have to include any libraries?
|
|
|
|
|
fvcker wrote: how do I use GetProcessID? I couldn't find any articles at MSDN!
The last letter is not supposed to be capital.
For more info:GetProcessId[^]
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
doesn't make a difference
|
|
|
|
|
Did you read the documentation I linked to?
I suppose not, because if you did you would have found out that you should not call ::GetProcessId() with a string as parameter, you call it providing a HANDLE to a process.
At this point it would do you much better if you explain what you're trying to do and why since this is at best pulled out of context.
You probably should enumerate the running processes, but that depends on what you're trying to do.
Have a look here[^] and here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
I'm trying to find the PID from the process name.
|
|
|
|
|
fvcker wrote: I'm trying to find the PID from the process name.
Yes, I figured that out, but why?
What are you going to do with that process ID?
Have you considered the possibility that there might be more than one instance of e.g. "cmd.exe" running? Which one would be the one you're interested in? How are you supposed to know?
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
|
fvcker wrote: I included...iostream...
Just out of curiosity, why would you think that would be it?
What OS are you using? Do you have the Platform SDK installed?
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Im using windows xp sp2. Platform SDK?
I included iostream because I was too lazy to remove it
|
|
|
|
|
fvcker wrote: Platform SDK?
Yes.
"Love people and use things, not love things and use people." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
|
Good Morning!
I have some code done in C. I'm building it using Visual C++, but there are some errors like:
Error 1 error C2054: expected '(' to follow 'SHARED_FUNCTION'
Error 2 error C2085: 'le16ToHost' : not in formal parameterlist
The function is declared like this:
SHARED_FUNCTION WORD le16ToHost( BYTE * src );
There's any problem with the way i'm declaring de function? Shared Functions are different in Visual C++?
Best regards.
|
|
|
|
|
How is it defined SHARED_FUNCTION (provided it is )?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
The function is provided like this:
WORD le16ToHost( BYTE * src )
{
return (src[0] ) |
(src[1] << 8 );
}
Hum... but the declaring is at .h file and the definition at .c file... Maybe a problem linking the header and the source code?
|
|
|
|
|
Actually have I asked about the 'SHARED_FUNCTION ' symbol. Where is it defined? How is it defined? Is it defined?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|