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 / Visual Studio.NET / General / August 2003

Tip: Looking for answers? Try searching our database.

[Help] How can I use C# to create a StdPicture Object for VB6?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Liu Qian - 26 Aug 2003 10:50 GMT
Hello, all!

I use OleCreatePictureIndirect API to create StdPicture, and the return is
S_OK, but the result seem not correct.

Here is my code:

[DllImport("olepro32.dll", SetLastError=true)]
internal static extern int OleCreatePictureIndirect(ref PICTDESC pPictDesc,
ref System.Guid riid, bool fOwn, ref stdole.IPictureDisp ppvObj);

internal struct PICTDESC{
  public long cbSizeOfStruct;
  public long picType;
  public long hPic;
  public long hpal;
 };

public StdPicture GetImage(int hHandle){

  PICTDESC pd = new PICTDESC();
  pd.cbSizeOfStruct = 144;//Marshal.SizeOf(pd);
  pd.hPic = hHandle;
  pd.hpal = 0;
  pd.picType = 1; // bitmap

  // Fill in magic IPicture GUID {7BF80980-BF32-101A-8BBB-00AA00300CAB}
  System.Guid iidIPicture = new
Guid("7BF80980-BF32-101A-8BBB-00AA00300CAB");

  stdole.IPictureDisp ipic = null;
  int nResult = OleCreatePictureIndirect(ref pd, ref iidIPicture, true, ref
ipic);

  //System.Diagnostics.Trace.WriteLine("Error: " +
Marshal.GetLastWin32Error());

  return (StdPicture)ipic;
}

The call of OleCreatePictureIndirect is OK, but the contents of ipic are
always "0". Anyone can help me or give some advises?

Thanks very much!

chian
Mattias Sj?gren - 26 Aug 2003 21:57 GMT
>[DllImport("olepro32.dll", SetLastError=true)]
>internal static extern int OleCreatePictureIndirect(ref PICTDESC pPictDesc,
[quoted text clipped - 6 lines]
>   public long hpal;
>  };

Your PICTDESC structure declaration is incorrect. Try it like this
instead.

[DllImport("olepro32.dll", PreserveSig=false)]
internal static extern void OleCreatePictureIndirect(ref PICTDESC
pPictDesc, ref System.Guid riid, bool fOwn, out stdole.IPictureDisp
ppvObj);

internal struct PICTDESC{
  public int cbSizeOfStruct;
  public int picType;
  public IntPtr hPic;
  public IntPtr hpal;
  public int _pad;
 };

>   pd.cbSizeOfStruct = 144;//Marshal.SizeOf(pd);

The structure size is definitely not 144 bytes. You better use
Marshal.SizeOf instead.

Mattias

Signature

Mattias Sjögren [MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Liu Qian - 27 Aug 2003 02:15 GMT
OK, Thanks Mattias.

The code worked correctlly, thank you very much.

chian

> >[DllImport("olepro32.dll", SetLastError=true)]
> >internal static extern int OleCreatePictureIndirect(ref PICTDESC pPictDesc,
[quoted text clipped - 29 lines]
>
> Mattias

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.