| | |
Casting Problem with FindMimeFromData Function
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 5
Reputation:
Solved Threads: 0
Hi,
I'm getting a casting error using the code below. The error on the web page (when you click the error icon) is:
Sys.WebForms.PageRequestManagerServerErrorExceptio n: Conversion from string "application.msword" to type "Long" is not valid.
It's to do with declaring the mimeout integer pointer to the "<MarshalAs(UnmanagedType.LPWStr)> ByRef ppwzMimeOut As String" value in the function call.
If I change mimeout declaration to: "Dim mimeout as string" and return that and comment out the other mimeout referenced code it returns "application/msword" correctly but obviously the rest of the function won't work because there is no pointer to the original referenced mimeout address.
Has anyone got any ideas of what I'm doing wrong?
Thanks,
Denise
I'm getting a casting error using the code below. The error on the web page (when you click the error icon) is:
Sys.WebForms.PageRequestManagerServerErrorExceptio n: Conversion from string "application.msword" to type "Long" is not valid.
It's to do with declaring the mimeout integer pointer to the "<MarshalAs(UnmanagedType.LPWStr)> ByRef ppwzMimeOut As String" value in the function call.
If I change mimeout declaration to: "Dim mimeout as string" and return that and comment out the other mimeout referenced code it returns "application/msword" correctly but obviously the rest of the function won't work because there is no pointer to the original referenced mimeout address.
Has anyone got any ideas of what I'm doing wrong?
Thanks,
Denise
ASP.NET Syntax (Toggle Plain Text)
Imports System.Security.Permissions Public Declare Function FindMimeFromData Lib "urlmon.dll" (ByVal pBC As IntPtr, <MarshalAs(UnmanagedType.LPWStr)> ByVal pwzUrl As String, <MarshalAs(UnmanagedType.LPArray, ArraySubType:=UnmanagedType.I1, SizeParamIndex:=3)> ByVal pBuffer As Byte(), ByVal cbSize As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByVal pwzMimeProposed As String, ByVal dwMimeFlags As Integer, <MarshalAs(UnmanagedType.LPWStr)> ByRef ppwzMimeOut As String, ByVal dwReserved As Integer) As Integer Public Shared Function getMimeFromFile(ByVal file As String) As String Dim mimeout As IntPtr If Not System.IO.File.Exists(file) Then Throw New FileNotFoundException(file + " not found") End If Dim MaxContent As Integer = CInt(New FileInfo(file).Length) If MaxContent > 4096 Then MaxContent = 4096 End If Dim fs As New FileStream(file, FileMode.Open) Dim buf(MaxContent) As Byte fs.Read(buf, 0, MaxContent) fs.Close() Dim result As Integer = FindMimeFromData(IntPtr.Zero, file, buf, MaxContent, Nothing, 0, mimeout, 0) If result <> 0 Then 'Throw Marshal.GetHRForExceptionresult) End If Dim mime As String = Marshal.PtrToStringUni(mimeout) Marshal.FreeCoTaskMem(mimeout) Return mime End Function
•
•
Join Date: Jul 2008
Posts: 5
Reputation:
Solved Threads: 0
Can nobody help me with this?
I've posted the same question in six forums and no-one seems to know what I've done wrong in my coding. I'm sure it's a simple case of using the wrong variable type either in the function or pointer declaration but for the life of me I don't know where!
Please advise.
Thanks.
I've posted the same question in six forums and no-one seems to know what I've done wrong in my coding. I'm sure it's a simple case of using the wrong variable type either in the function or pointer declaration but for the life of me I don't know where!
Please advise.
Thanks.
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: Gridview footer not showing
- Next Thread: calculate allowance
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax appliances application asp asp.net beginner box browser businesslogiclayer button c# c#gridviewcolumn cac checkbox child class compatible confirmationcodegeneration content contenttype control countryselector courier css database datagrid datagridview datalist deadlock deployment development dgv dialog dropdownmenu dynamic dynamically edit embeddingactivexcontrol feedback fileuploader fill findcontrol flash flv form forms grid gridview gudi homeedition hosting iis image javascript jquery list menu mssql multistepregistration nameisnotdeclared novell objects opera order problem ratings redirect registration relationaldatabases rotatepage search security select serializesmo.table sessionvariables silverlight smoobjects sql ssl tracking treeview typeof validatedate validation vb.net virtualdirectory vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment wizard xml xsl





