Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2005

Tip: Looking for answers? Try searching our database.

C# Win32 Interop -  LVM_GETITEMTEXT does not work

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
janhavib@yahoo.com - 10 Aug 2005 11:45 GMT
Hi,

I'm trying to access listview control in a VB application from C#
application.
Follwoing is my code
StructLayoutAttribute(LayoutKind.Sequential)]
public struct LV_ITEM
{
public UInt32 mask;
public Int32 iItem;
public Int32 iSubItem;
public UInt32 state;
public UInt32 stateMask;
public String pszText;
public Int32 cchTextMax;
public Int32 iImage;
public IntPtr lParam;
}const int BUFFER_SIZE = 512;

LV.iItem = 3;
LV.mask = Win32API.LVIF_IMAGE;
LV.cchTextMax = 255;
LV.iSubItem = 0;
LV.pszText = new String('\0', 255);

Win32API.SendMessage(hWnd, Win32API.LVM_GETITEMTEXT, 3, ref LV);
string text = LV.pszText.ToString();

My definations are as given below.

const int LVM_FIRST  = 0x1000;
const int LVM_GETITEMCOUNT = LVM_FIRST + 4;
const int LVM_GETITEM  = LVM_FIRST + 5;
const int LVIF_TEXT  = 0x0001;
LVM_GETITEMTEXT = (LVM_FIRST + 45);

[DllImport("user32.dll")]
static extern int SendMessage(IntPtr window, int message, int wparam,
ref LV_ITEM lparam);

My Problem is pszText always returns empty string.
Please help.

Thanks in advance.
J
Vadym Stetsyak - 10 Aug 2005 12:27 GMT
It is necessary to add attributes to

[MarchalAs(UnmanagedType.LPStr)]
public String pszText;

Signature

Vadym Stetsyak aka Vadmyst

> Hi,
>
[quoted text clipped - 41 lines]
> Thanks in advance.
> J
janhavib@yahoo.com - 11 Aug 2005 13:17 GMT
Tried that. Still it doesnt work. Is this because the listview I'm
trying to access is in some other process?
Vadym Stetsyak - 15 Aug 2005 11:44 GMT
How do you think you will access memory from another process?
If you from process A send message to the process B, who allocates memory,
and returns pointer to the memory within the structure - you will not get
that memory.

However, every process has it own virtual address space, so, that other
processes couldn't access the memory.

AFAIK if you want to interchange data with another process, there are
numerous IPC methods ( WM_COPYDATA, memmory mapped files, sockets, pipes
etc )

Signature

Vadym Stetsyak aka Vadmyst

> Tried that. Still it doesnt work. Is this because the listview I'm
> trying to access is in some other process?
Charles Law - 01 Sep 2005 09:34 GMT
Have a look here:

http://www.codeproject.com/threads/int64_memsteal.asp

The example is in C, but should be convertible.

HTH

Charles

> Tried that. Still it doesnt work. Is this because the listview I'm
> trying to access is in some other process?

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.