|
Hi everybody. I've been working at an article about Inter-Process communication that I also intend to post here when finished ::- ). However, I do have one last issue to solve. A quite difficult issue. I want to pass an array from VC++ to VB. From VB to VC++ I made it work quite easy, but I am having trouble doing it the other way around.
As I learned, Visual Basic works with array using SAFEARRAYs. Now. For example, to call a VB function from a VC++ DLL you gotta do this:
void CallVBFunctionForNumber (long lSomeValueToSend)<br />
{<br />
typedef void (__stdcall *OutsideFunction)(long AValue);
OutsideFunction FunctionCall;
FunctionCall = (OutsideFunction)extNumberProc;
FunctionCall(lSomeValueToSend);
}
extNumberProc is an address which was previously received from VB. To call that function all you gotta do in VC++ is this:
CallVBFunctionForNumber(20);
And now here's the function for calling a function from Visual Basic which should accept an array. First, here's the VB function.
'FUNCTION CALLED FROM THE VC++ DLL.<br />
Public Sub ArrayDemoFunction(ByRef Something As Variant)<br />
MsgBox Something(2)<br />
End Sub
and the VC++ function
void CallVBFunctionForArray ()<br />
{<br />
typedef void (__stdcall *OutsideFunction)(VARIANT *AValue);
OutsideFunction FunctionCall;
FunctionCall = (OutsideFunction)extArrayProc;
<br />
VARIANT *pVariant = NULL;
SAFEARRAY *sarrVC;
SAFEARRAYBOUND sabBound = { 10, 0 };
<br />
VariantInit (pVariant);
pVariant->vt = VT_ARRAY | VT_I4;
sarrVC = SafeArrayCreate(VT_I4, 1, &sabBound);
for (long iCounter = 0; iCounter < 10; iCounter++)
SafeArrayPutElement(sarrVC, &iCounter, &iCounter);<br />
pVariant->parray = sarrVC;
FunctionCall(pVariant);
}
Executing the above VC++ function works, until calling the VB function. When that happens, everything comes crashing down with an "Unhandled exception in Testapp.exe (OLEAUT32.DLL): 0xC00000005: Access Violation.".
For your reference, here's an article which I used to create the code:
http://www.microsoft.com/msj/0599/wicked/wicked0599.aspx[^]
So... ideas anybody? ::- )
-= E C H Y S T T A S =-
The Greater Mind Balance
-- modified at 1:44 Friday 4th November, 2005
|
|
|
|
|
Try adding VT_BYREF to the vt for your variant
pVariant->vt= VT_ARRAY | VT_I4 | VT_BYREF
Just a thought.
|
|
|
|
|
Hello, everyone!
Who can tell me , what's the meaning of "USES_CONVERSION"?
Thanks a lot!
|
|
|
|
|
|
You are so kind.
Thank you and best regards.
|
|
|
|
|
I want to close the dialog, when i clicked outside.
|
|
|
|
|
Response this message WM_NCMBUTTONDOWN ;
d
|
|
|
|
|
I've tried both WM_NCMBUTTONDOWN and WM_NCLBUTTONDOWN, but neither works.
|
|
|
|
|
Hi
You need to lock the mouse cursor to your windows.
During this lock all messages will be parsed by you.
In the close function you can relase the mouse
If you use MFC you can call CWnd::SetCapture like this
<br />
BOOL CMyDlg::OnInitDialog()<br />
{<br />
...<br />
this->SetCapture();<br />
...<br />
}<br />
You then need to capture the WM_LBUTTONUP message since the whole desktop is now client arrea you will get this message then simply check whether the point is your window rectangle or not.
<br />
void CdlgcloseDlg::OnLButtonUp(UINT nFlags, CPoint point)<br />
{<br />
CRect rtWnd;<br />
GetWindowRect(&rtWnd);<br />
ScreenToClient(&rtWnd);<br />
<br />
if(!rtWnd.PtInRect(point))<br />
{<br />
ReleaseCapture();<br />
PostQuitMessage(0); <br />
} <br />
<br />
CDialog::OnLButtonUp(nFlags, point);<br />
}<br />
If you use the win32 API the funtions are:
<br />
SetCapture(HWND hWnd);<br />
ReleaseCapture();<br />
Hope that this is what you needed
codito ergo sum
|
|
|
|
|
I do it this way, but the controls in the dialog doesn't receive messages.
-- modified at 7:30 Friday 4th November, 2005
|
|
|
|
|
hi,
where do you capture the WM_LBUTTONUP (or DOWN) messages, in the messageloop of the dialog or in one of the child controls.
If you capture/process it in the messageloop of the dialog it should, work
I tried it with a small sample app and didn't get any problems
codito ergo sum
|
|
|
|
|
Could you send me your app source? I'm cofused.
|
|
|
|
|
There is no SetCapture?
Could you send me the whole project in an attachment? I want to try it. Thanks.
|
|
|
|
|
There is no SetCapture in the fragment.
Could send the whole project to me? I want to try it. Thank you.
|
|
|
|
|
|
Might be it is stored in the registery
have u tried to search that .
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
How to show File properties dialog and delete to recycle bin dialog(Confirm file delete dlg)?
I want to do these just from the full file path.
And how to rename a file using system method?
Thank you.
|
|
|
|
|
use GetFileAttributesEx to obtains special attributes.
d
|
|
|
|
|
Thank you for your reply.
I mean that I just want to show the peoperty dialog. I don't need to get the file property .
|
|
|
|
|
SHMultiFileProperties
My blogs:
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
I need to display a dialog box in the default desktop in windows XP with multiple desktops.
Could anybody help me?
- NS -
|
|
|
|
|
I create a big file, using the SetEndofFile, then i Seek the filepointer and write some data in it, but i found the func WriteFile take a long time, Why?
HANDLE hFile = CreateFile(_T("D:\\writetest.dat"),
GENERIC_WRITE,
FILE_SHARE_WRITE|FILE_SHARE_READ,
NULL,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS,
NULL);
LARGE_INTEGER llPos, llNew;
llPos.QuadPart = 2000*1024;
llPos.QuadPart *= 1024;
SetFilePointerEx(hFile, llPos, &llNew, FILE_BEGIN);
SetEndOfFile(hFile);
llPos.QuadPart = 1800*1024;
llPos.QuadPart *= 1024;
SetFilePointerEx(hFile, llPos, &llNew, FILE_BEGIN);
DWORD dwBytes = 256 * 1024;
BYTE * pBuffer = new BYTE[dwBytes];
DWORD dwBytesWritten;
DWORD dwBegin = GetTickCount();
WriteFile(hFile, pBuffer, dwBytes, &dwBytesWritten, NULL);
DWORD dwTime = GetTickCount() - dwBegin;
CString strTime;
strTime.Format(_T("Time: %d"), dwTime);
AfxMessageBox(strTime);
delete []pBuffer;
CloseHandle(hFile);
|
|
|
|
|
Thats' a big file alright. So it will take it's time to handle.
But you might speed it up by replacing FILE_FLAG_RANDOM_ACCESS with FILE_FLAG_SEQUENTIAL_SCAN or FILE_FLAG_WRITE_THROUGH.
I suspect FILE_FLAG_SEQUENTIAL_SCAN will give the most performance gain. (You aren't really doing random access of the file, just sequential writing).
|
|
|
|
|
I tried to use the flag, but unfortunately, it's no effect.
|
|
|
|
|
OK, then I'm out of ideas.
Except for the usual: Get a faster machine and a faster hard disk.
|
|
|
|