473,769 Members | 7,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Data Marshaling Problem

1 New Member
Hi all,

I am dot net new user.I am trying to use active x control from vc 6.0 in dot net.I have data marshaling problem in combination dot net and ocx from vc 6.0.

The following is the function in vc 6.0 ocx.Function name is myRetrieve Image.

BOOL CICACtrl::Retri eveImage(long iEventID, long iImageID, const VARIANT FAR& Image, short FAR* iWidth, short FAR* iHeight, short FAR* iDepth)
{

if(switchFlag == 0)
{
return false;
}

// TODO: Add your dispatch handler code here
TRY
{
TRY
{
LPCTSTR Address = "localhost" ;
LPCTSTR DBName = "TeleIntdb" ;
LPCTSTR UserName = "root";
//LPCTSTR PassWord = "cambridge" ;
LPCTSTR PassWord = "12345678";
//UINT Port = UINT(iPort);
UINT Port = 0;
m_connGetImg.Op en(Address, DBName, UserName, PassWord, Port);
}
CATCH(CSQLExcep tion, e)
{
//e->ReportError( );
return false;
}
END_CATCH;

int i;
long ImgIDArr[6] = {0,0,0,0,0,0};
CSQLResult res1(m_connGetI mg);
SQLValueArray arrValues1;
arrValues1.SetS ize(1); //number of columns

res1.QueryV(_T( "SELECT ImageID FROM ImageTbl WHERE EventImgID = %d"), iEventID);

i=0;
while (res1.Fetch(arr Values1))
{
ImgIDArr[i] = arrValues1.GetA t(0);
++i;
}

// check
if (iImageID > i)
{
m_connGetImg.Cl ose();
return false;
}

CSQLResult res(m_connGetIm g);
SQLValueArray arrValues;
arrValues.SetSi ze(1); //number of columns
unsigned char* buff;
SafeArrayAccess Data (Image.parray, (void**)&buff);
res.QueryV(_T(" SELECT Image FROM ImageTbl WHERE EventImgID = %d AND ImageID = %d"), iEventID, ImgIDArr[iImageID-1]);

while (res.Fetch(arrV alues))
{
memcpy(buff, arrValues.GetAt (0), arrValues.GetAt (0).m_nLength); //22035, 82726
}
SafeArrayUnacce ssData (Image.parray);
*iWidth = 10;
*iHeight = 10;
*iDepth = 10;

m_connGetImg.Cl ose();
return true;
}
CATCH(CSQLExcep tion, e)
{
//AfxMessageBox(" catch 2");
m_connGetImg.Cl ose();
//e->ReportError( );
return false;
}
END_CATCH;
}


The data type ( VARIANT FAR& ) is changed in RCW as System.Object.

I call this function in vb.net as



Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button3.Click

Dim image1 As New Object

Dim Img(3000000) As Byte
Dim w As Integer
Dim h As Integer
Dim d As Integer
Dim RetrieveImageRe tVal As Boolean
Dim EventID As Long
Dim ImageID As Long
Dim i As Integer



gdViewer1.Clear ()
gdViewer1.Close Picture()

EventID = CLng(TextBox4.T ext)
ImageID = CLng(TextBox5.T ext)





RetrieveImageRe tVal = AxICA1.Retrieve Image(EventID, ImageID, image1, w, h, d)

TextBox6.Text = w
TextBox7.Text = h
TextBox8.Text = d


Dim objMS As New MemoryStream()
Dim objBinaryFormat ter As New BinaryFormatter ()
objBinaryFormat ter.Serialize(o bjMS, image1)
Img = objMS.GetBuffer ()



Dim fs As FileStream
fs = New FileStream("c:\ ICATmpPic.jpg", FileMode.Create , FileAccess.Read Write)

For i = 0 To Img.Length - 1
fs.WriteByte(Im g(i))
Next
fs.Close()


gdViewer1.Displ ayFromFile("c:\ ICATmpPic.jpg")

End Sub


Error occured in call of RetrieveImage.

Width(w),Height (h) and Depth(d) is Ok but Image(image1) is not Ok.
What should I do.Please inform me about this problem.My email is kyawkoko.ko@gma il.com.
Aug 7 '07 #1
0 1083

Sign in to post your reply or Sign up for a free account.

Similar topics

1
947
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to type in C# or VB.NET) be garbage collected? Similarily, if C# or VB.NET pass SAFEARRAY to the COM object via COM method invocation, will this SAFEARRAY be garbage collected after the call? My guess to answers for both questions is yes. Thanks.
1
2067
by: madhununna | last post by:
I'm trying to parse string data using castor and it looks like the new lines are getting lost. I'm using castor 0.9.4.3 For example: Input <INPUT> First line
4
11707
by: Vadym Stetsyak | last post by:
Hi there!!! I'm looking for any resources on the subject. Any help will be appreciated! -- Vadym Stetsyak ICQ 161730125 He, who commands the past - commands the future
3
1312
by: Stephen Gennard | last post by:
Hello, I having a problem dynamically invoking a static method that takes a reference to a SByte*. If I do it directly it works just fine. Anyone any ideas why? I have include a example below... --
3
3645
by: Rudy Velthuis | last post by:
Hello, Does anyone know how to create a struct that will marshal to the following C++ struct A, containing an array of the user defined String10 type: struct String10 { char SLen; char S;
1
2677
by: Bill Medland | last post by:
I am trying to do some P/Invoke custom marshaling and am looking for a little help on custom marshaling a value type. I am working based on Kate Gregory's "Arranging Custom Marshaling With P/Invoke", which is unfortunately in C++ with managed extensions; I am working in C#. As with Kate's example I want to marshal from a System.DateTime to a proprietary format. However I cannot figure out how to tell the system to box the DateTime. ...
1
3030
by: _DD | last post by:
Existing problem: A function that runs on a thread needs to return data to the UI thread. When the data is returned, that will trigger secondary tasks, including access to form controls and lookup of data within a database. I'm not sure of the implications of using data returned by the thread within database access code, but I do know about InvokeRequired() etc for access to forms controls. I've used that often when individual...
0
1876
by: jpogorman | last post by:
Hello, I am trying to get c# custom marshaling working in a particular scenario but it does not appear to be working or not jumping into my marshaling class when I try to debug it. I am try to implement a performance improvement in the transfer of thousands of objects (ClientInfoDescriptor) over a remote call. The objects all have a model object (IDataDrivenModel) to describe them but there may only two or three model objects in total. These...
11
3823
by: itdevries | last post by:
Hi, I'm trying to convert some char data I read from a binary file (using ifstream) to a float type. I've managed to convert the int types but now I need to do the float types as well but it doesn't seem to work. The code below is what I'm trying to use. Anyone see any obvious errors? or have any hints/pointers? regards, Igor float floatRead = 0;
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10219
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8876
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3567
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.