Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

AccessViolationException bei Marshal.StructureToPtr

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

bei mir kommt es bei follgendem Code zu einer "AccessViolationException".


Dim stDMVar_Filter As DllCallsAndTypes.ODK.DataManager.DM_VARFILTER

stDMVar_Filter.dwFlags = DM_VARFILTER_ENUM.DM_VARFILTER_NAME

stDMVar_Filter.dwNumTypes = 0

stDMVar_Filter.lpszConn = ""

stDMVar_Filter.lpszGroup = ""

stDMVar_Filter.lpszName = "*"

stDMVar_Filter.pdwTypes = IntPtr.Zero

Dim ptrVarFilter As IntPtr = Marshal.AllocHGlobal(Marshal.SizeOf(GetType(DM_VARFILTER)))

Marshal.StructureToPtr(stDMVar_Filter, ptrVarFilter, True) '<-- HIER EXCEPTION

Die Deklaration in C von der Struktur ist diese:

typedef struct {

    DWORD    dwFlags;

    DWORD    dwNumTypes;

    LPDWORD pdwTypes;

    LPSTR       lpszGroup;

    LPSTR       lpszName;

    LPSTR       lpszConn;

} DM_VARFILTER;

In VB habe ich die Struktur wie follgt angelegt:

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Ansi, Pack:=1)>

Public Structure DM_VARFILTER


    <MarshalAs(UnmanagedType.U4)>

    Public dwFlags As DM_VARFILTER_ENUM '4      004


    <MarshalAs(UnmanagedType.U4)>

    Public dwNumTypes As UInt32         '4      008


    Public pdwTypes As System.IntPtr    '4      012


    <MarshalAs(UnmanagedType.LPStr)>

    Public lpszGroup As [String]        '4      016

    <MarshalAs(UnmanagedType.LPStr)>

    Public lpszName As [String]         '4      020

    <MarshalAs(UnmanagedType.LPStr)>

    Public lpszConn As [String]         '4      024

End Structure

Wenn ich die Struktur ausrechne, komme ich auf 24 Byte. Diese werden auch mit

Marshal.AllocHGlobal alloziert (siehe Bildchen im Anhang).

Was habe ich nicht beachtet, dass es zu einer Access Violation kommt.

vG raiserle

post-60086-14430449909416_thumb.png

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.