Windows mobile 如何从WinMO6的Aygshell.dll中pInvoke函数SHCameraCapture(摄影机对话框)

Windows mobile 如何从WinMO6的Aygshell.dll中pInvoke函数SHCameraCapture(摄影机对话框),windows-mobile,pinvoke,camera,Windows Mobile,Pinvoke,Camera,我需要通过pinvoking SHCameraCapture从dll Aygshell.dll中显示compact framework 3.7应用程序中的相机捕获对话框。我无法使用托管对象CameraCaptureDialog,因为我使用的技术存在局限性。相反,我需要通过Pinvoking访问它 有关此函数的文档,请参阅。该函数接受一个定义对话框参数的结构。e、 g.在何处保存文件,使用何种分辨率 我会想象我必须在C#中定义一个struct的副本,并用StructLayout属性装饰sturct

我需要通过pinvoking SHCameraCapture从dll Aygshell.dll中显示compact framework 3.7应用程序中的相机捕获对话框。我无法使用托管对象CameraCaptureDialog,因为我使用的技术存在局限性。相反,我需要通过Pinvoking访问它

有关此函数的文档,请参阅。该函数接受一个定义对话框参数的结构。e、 g.在何处保存文件,使用何种分辨率


我会想象我必须在C#中定义一个struct的副本,并用StructLayout属性装饰sturct。我还设想代码将涉及[DllImport(“aygshell.dll”)]。任何关于如何调用此函数的示例代码都将不胜感激。

我无法测试此代码,但您的结构/函数应该如下所示:

struct SHCAMERACAPTURE {
  public Int32 cbSize;
  public IntPtr hwndOwner;

  [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]  
  public string szFile;

  [MarshalAs(UnmanagedType.LPStr)] 
  string pszInitialDir;

  [MarshalAs(UnmanagedType.LPStr)] 
  string pszDefaultFileName;

  [MarshalAs(UnmanagedType.LPStr)] 
  string pszTitle;

  Int32 StillQuality;
  Int32 VideoTypes;
  Int32 nResolutionWidth;
  Int32 nResolutionHeight;
  Int32 nVideoTimeLimit;
  Int32 Mode;
}

[DllImport("aygshell.dll")]
static extern int SHCameraCapture(ref SHCAMERACAPTURE pshcc);
另外,您不需要在SHCAMERCAPTURE上显式设置StructLayout,因为它的布局没有什么不寻常的地方


一旦你成功了,你可能想把你的发现发布到pinvoke.net上,让其他人利用

糟糕,这是个好的开始。。。谢谢你让这个开始。我试着把它连接起来,但得到了一个NotSupportedException

我已将测试应用程序中的文本粘贴到下面。注意,我尝试用[StructLayout(LayoutKind.Sequential)]装饰结构。我还公开了所有成员,以消除对象可访问性方面的任何问题

public partial class Form1 : Form
{
    [DllImport("aygshell.dll")]
    static extern int SHCameraCapture(ref SHCAMERACAPTURE pshcc);

    [StructLayout(LayoutKind.Sequential)]
    struct SHCAMERACAPTURE
    {
        public Int32 cbSize;
        public IntPtr hwndOwner;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
        public string szFile;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pszInitialDir;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pszDefaultFileName;
        [MarshalAs(UnmanagedType.LPStr)]
        public string pszTitle;
        public Int32 StillQuality;
        public Int32 VideoTypes;
        public Int32 nResolutionWidth;
        public Int32 nResolutionHeight;
        public Int32 nVideoTimeLimit;
        public Int32 Mode;
    }
    private void ShowCamera()
    {
        SHCAMERACAPTURE captureData = new SHCAMERACAPTURE
                                           {
                                               cbSize = sizeof (Int64),
                                               hwndOwner = (IntPtr)0,
                                               szFile = "\\My Documents",
                                               pszDefaultFileName = "picture.jpg",
                                               pszTitle = "Camera Demo",
                                               StillQuality = 0,
                                               VideoTypes = 1,
                                               nResolutionWidth = 480,
                                               nResolutionHeight = 640,
                                               nVideoTimeLimit = 0,
                                               Mode = 0
                                           };
        SHCameraCapture(ref captureData);
    }
    private void button1_Click(object sender, EventArgs e)
    {
        ShowCamera();
    }
这段代码有效

#region Enumerations

public enum CAMERACAPTURE_STILLQUALITY
{
    CAMERACAPTURE_STILLQUALITY_DEFAULT = 0,
    CAMERACAPTURE_STILLQUALITY_LOW = 1,
    CAMERACAPTURE_STILLQUALITY_NORMAL = 2,
    CAMERACAPTURE_STILLQUALITY_HIGH = 3
}
public enum CAMERACAPTURE_VIDEOTYPES
{
    CAMERACAPTURE_VIDEOTYPE_ALL = 0xFFFF,
    CAMERACAPTURE_VIDEOTYPE_STANDARD = 1,
    CAMERACAPTURE_VIDEOTYPE_MESSAGING = 2
}

public enum CAMERACAPTURE_MODE
{
    CAMERACAPTURE_MODE_STILL = 0,
    CAMERACAPTURE_MODE_VIDEOONLY = 1,
    CAMERACAPTURE_MODE_VIDEOWITHAUDIO = 2
}

#endregion //Enumerations

#region Structures

[StructLayout(LayoutKind.Sequential,CharSet=CharSet.Unicode)]
public struct struSHCAMERACAPTURE
{
    public uint cbSize;
    public IntPtr hwndOwner;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
    public String szFile;
    [MarshalAs(UnmanagedType.LPTStr)]
    public String pszInitialDir; //LPCTSTR
    [MarshalAs(UnmanagedType.LPTStr)]
    public String pszDefaultFileName; //LPCTSTR
    [MarshalAs(UnmanagedType.LPTStr)]
    public String pszTitle;  //LPCTSTR
    public CAMERACAPTURE_STILLQUALITY StillQuality;
    public CAMERACAPTURE_VIDEOTYPES VideoTypes;
    public uint nResolutionWidth;
    public uint nResolutionHeight;
    public uint nVideoTimeLimit;
    public CAMERACAPTURE_MODE Mode;
}
#endregion //Structures

#region API
[DllImport("Aygshell.dll", SetLastError = true,CharSet=CharSet.Unicode)]
public static extern int SHCameraCapture
(
    ref struSHCAMERACAPTURE pshCamCapture
);

private string StartImager(String strImgDir, String strImgFile, uint uintImgHeight,
                            uint uintImgWidth)

try
{
  struSHCAMERACAPTURE shCamCapture = new struSHCAMERACAPTURE();

  shCamCapture.cbSize = (uint)Marshal.SizeOf(shCamCapture);
  shCamCapture.hwndOwner = IntPtr.Zero;
  shCamCapture.szFile = "\\" + strImgFile;  //strImgDir + "\\" + strImgFile;
  shCamCapture.pszInitialDir = "\\"; // strImgDir;
  shCamCapture.pszDefaultFileName = strImgFile;
  shCamCapture.pszTitle = "PTT Image Capture";
  shCamCapture.StillQuality = 0; // CAMERACAPTURE_STILLQUALITY.CAMERACAPTURE_STILLQUALITY_NORMAL;
  shCamCapture.VideoTypes = CAMERACAPTURE_VIDEOTYPES.CAMERACAPTURE_VIDEOTYPE_STANDARD;
  shCamCapture.nResolutionHeight = 0; // uintImgHeight;
  shCamCapture.nResolutionWidth = 0; // uintImgWidth;
  shCamCapture.nVideoTimeLimit = 10;
  shCamCapture.Mode = 0; // CAMERACAPTURE_MODE.CAMERACAPTURE_MODE_STILL;

  //IntPtr intptrCamCaptr = IntPtr.Zero;

  //Marshal.StructureToPtr(shCamCapture, intptrCamCaptr, true);

  int intResult = SHCameraCapture(ref shCamCapture);
  if (intResult != 0)
  {
      Win32Exception Win32 = new Win32Exception(intResult);
      MessageBox.Show("Error: " + Win32.Message);
  }             

  return strCaptrErr;
}

catch (Exception ex)
{
    MessageBox.Show("Error StartImager : " + ex.ToString() + " - " + strCaptrErr
                    , "Nomad Imager Test");
    return "";
}

嗯,恐怕我无法尝试代码,因为我还没有安装compact framework。但是,“\\My Documents”是一个shell文件夹,不是有效的文件系统路径。尝试在那里使用完整的文件系统路径。(除非紧凑框架中的工作方式不同,否则请忽略!)@Groky:你错了,这是一条道路。设备没有驱动器号。